我想使用django-modeltranslation翻译django应用程序(1.11)中的name
字段。我想翻译为en和fr,但在管理面板中,我得到3个字段而不是2个:name
,name_en
,name_fr
。
models.py
class Country(models.Model):
name = models.CharField(max_length=100)
code = models.SlugField(max_length=20, default='')
def __str__(self):
return self.name
admin.py
class CountryAdmin(admin.ModelAdmin):
list_display = ('name_en',)
translation.py
from events.models import Country
class CountryTranslationOptions(TranslationOptions):
fields = ('name',)
translator.register(Country, CountryTranslationOptions)
答案 0 :(得分:2)
请按照
从TranslationAdmin(而不是admin.ModelAdmin)继承您的管理模型http://django-modeltranslation.readthedocs.io/en/latest/admin.html
F。你应该
from modeltranslation.admin import TranslationAdmin
class CountryAdmin(TranslationAdmin):
list_display = ('name',)