开发者

Django model i18n of content

In my design there are some models where I need to store certain fields in different languages. Has it be done before? I saw some Django modules that help do model translations but some of them did not work properly.

Any best practices out there? Below is my code.

My model,

class Lookup_I18n(models.Model):
    i18n_code = models.CharField(max_length=5, default=settings.LANGUAGE_CODE)
    val开发者_如何学Pythonue = models.CharField(max_length=300)

class Lookup(models.Model):

    purpose = models.CharField(max_length=10)
    key = models.CharField(max_length=10)
    value_i18n = models.ForeignKey(Lookup_I18n)
    value = models.Field()

    class Meta:
        unique_together = (('purpose', 'key'),)


I used recently django_modeltranslation. It will create extra fields in each table for for translation of a field in a certain language. You can provide the translation through Django admin panel. Here are some applications for Django that translate the models. I had to translate just a field in the model and it worked. Choose the application that suits best with your design.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜