1

I want to translate the name field in the django application (1.11) using django-modeltranslation. I want to translate to en and fr, but in the admin panel I get 3 fields instead of two: 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)
user9192656
  • 549
  • 3
  • 16

1 Answers1

3

Please inherit yout admin models from TranslationAdmin (instead of admin.ModelAdmin) as per

http://django-modeltranslation.readthedocs.io/en/latest/admin.html

F. e you shoud have

from modeltranslation.admin import TranslationAdmin

class CountryAdmin(TranslationAdmin):
    list_display = ('name',)
Serafeim
  • 14,962
  • 14
  • 91
  • 133