Django modeltranslation queries fallback

后端 未结 2 1794
走了就别回头了
走了就别回头了 2020-12-20 18:36

I\'m using django modeltranslation for a multi-language site.

Language fallback works good when reading attributes directly. For example, if current language is Germ

2条回答
  •  我在风中等你
    2020-12-20 19:28

    You must ensure that your model is registered in translation.py

    from modeltranslation.translator import register, TranslationOptions
    @register(YourModel)
    class YourModel(TranslationOptions):
        pass
    

    In this way all the queries that are done will return the appropriate field depending on the language in which it is, this because to register it is created a MultilingualManager

提交回复
热议问题