Customize "verbose_name" for embedded administrators (admininline)

0

I have several models with foreign keys to other models, which embed in the administrator of that model using obviously admin.StakedInline , the problem is that the same model has up to two child models of the same type, so I have to embed two administrators of the same model but with different fk_name : Embedded administrators

class StatsEditionInline(admin.TabularInline):
    model = StatsEdition
    verbose_name = _('Stats')


class ChampionCupInLine(admin.TabularInline):
    model = Edition
    fk_name = 'champion'
    verbose_name = _("Cup's Champion")


class LocationCupInLine(admin.TabularInline):
    model = Edition
    fk_name = 'location'
    verbose_name = _("Cup's location")


class MatchTeamOneInline(admin.TabularInline):
    model = Match
    fk_name = "team_1"
    verbose_name = _("Country's Matches as Team 1")


class MatchTeamTwoInline(admin.TabularInline):
    model = Match
    fk_name = "team_2"
    verbose_name = _("Country's Matches as Team 2")


class MatchCupInline(admin.TabularInline):
    model = Match
    fk_name = 'cup'
    verbose_name = _("Cup's Matches")

Main administrator:

@admin.register(Country)
class CountryAdmin(admin.ModelAdmin):
    fieldsets = [
        (_('Description'),
         {'fields':
              ['slug', 'name', 'area']
          }
         ),
        (_('Stats'),
         {'fields':
              ['mp', 'agm', 'fg', 'ufg']
          }
         ),
    ]

    inlines = [LocationCupInLine, ChampionCupInLine, StatsEditionInline, MatchTeamOneInline, MatchTeamTwoInline]

    list_display = ['slug', 'name', 'area', 'mp', 'agm', 'fg', 'ufg', 'cups_counter', 'location_counter']
    list_filter = ['name', 'area', 'mp', 'agm', 'fg', 'ufg']
    list_editable = ['slug', 'name', 'area', 'mp', 'fg', 'ufg']
    search_fields = ['name', 'area', 'mp', 'agm', 'fg', 'ufg']
    prepopulated_fields = {"slug": ("name",)}

    def cups_counter(self, obj):
        return obj.cups.all().count()

    cups_counter.short_description = _('Cups')
    cups_counter.allow_tags = True

    def location_counter(self, obj):
        return obj.location.all().count()

    location_counter.short_description = _('Location')
    location_counter.allow_tags = True

The problem comes when I have to differentiate each administrator embedded by the role that inline exerts: It is clear in the name, it is one thing to count the Country as a Champion of a cup, to count it as the Seat of the Cup.

For this I use verbose_name for each of them, as you can see in the embedded, the problem is that directly in the template does not print the personalized title:

As you can see, no one difference is different from another, there are two repeated names, but they bring completely different models.

How can I customize the verbose_name of an embedded administrator? Is there a limitation of the last version of Django that prevents the titles from being customized correctly?

    
asked by SalahAdDin 27.05.2016 в 19:28
source

1 answer

1

The descriptive name or verbose_name applies to querys that only return a single result. When the 'query' has more than one result it is necessary to apply the plural descriptive name, that is, the verbose_name_plural , which is the one that the administrator system will use in case the query have more than 1 result.

So when adding a verbose_name the best thing is to add additional verbose_name_plural .

    
answered by 08.06.2016 / 19:31
source