Skip to content Skip to sidebar Skip to footer

Remove Or Edit Object Name In Admin.tabularinline

My tabular inline in the admin looks like this : How do I get rid of the DateDeCotisation_adherents object phrase ? For bonus points, why are there three empty lines at the bottom

Solution 1:

That inline should take the verbose_name and verbose_name_plural from the inner Meta class of the model according to the documentation. Yet, i just dumped your code into the latest django and it actually doesn't (or, maybe, it only doesn't do it when you use .through, nevertheless).

Fortunately, you can always override that by setting verbose_name and verbose_name_plural directly inside the InlineModelAdmin, i.e.

classDatesDeCotisationInline(admin.TabularInline):
    model = DateDeCotisation.adherents.throughreadonly_fields= ['datedecotisation']
    can_delete = Falseverbose_name='date de cotisation for adherent'
    verbose_name_plural = 'date de cotisation for adherent'classAdherentAdmin(admin.ModelAdmin):
    inlines = [DatesDeCotisationInline]

admin.site.register(models.Adherent, AdherentAdmin)

(Sorry for the "for" there but i do not speak French)

The admin appears as follows in Django 1.10:

django tabular inline


On a small note you shall never need to do .encode('utf-8') in python 3. Its stings are UTF-8 by default.

class Meta:
    verbose_name = "date de cotisation".encode('utf-8')
    verbose_name_plural = "dates de cotisation".encode('utf-8')

(I assume you're on python 3 since you're using __str__)

Solution 2:

In Django 3, the title of each object for inline admin (DateDeCotisation_adherents object in the original post) comes from the model's __str__ method. Also the extra lines are likely because of the extra attribute of the inline admin class. The default set in admin.InlineModelAdmin (parent of Stacked and Tabular inline) has extra = 3. In your inline admin, set extra = 0. Feel free to take a look at all the options in django.contrib.admin.options.py.

Post a Comment for "Remove Or Edit Object Name In Admin.tabularinline"