user9192656
user9192656

Reputation: 579

Django modeltranslation too many fields

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)

Upvotes: 1

Views: 579

Answers (1)

Serafeim
Serafeim

Reputation: 15104

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',)

Upvotes: 3

Related Questions