This is kind of a silly question, but I have a couple models that have a many-to-many relationship, and am using Inline's to allow administration of these models in the Django Admin. The labels that are shown for these Inlines don't seem to be affected at all by the Model Meta attributes like other sections of the Admin are. The Admin interface is going to be used by non-programmers, and I would rather them not have to look at sections with labels like "User-Feature relationships," which contain rows titled "User_feature objects". This there a way to change these?
Asked
Active
Viewed 7,182 times
7
-
Does the Model has an __unicode__ method defined? – Paulo Scardine Jun 17 '11 at 04:06
-
Yes, all my models have \_\_unicode\_\_ methods. Those don't seem to factor in to the labels at all, at least not in the Many-to-many Inlines. – Jun 17 '11 at 04:11
1 Answers
16
Django automatically generate intermediate model for m2m relationship, and creates verbose name as '%(from)s-%(to)s relationship' marked for translation. One can use more suitable translation to affect change on the whole site. Gettext definition to look for are:
'%(from)s-%(to)s relationship'
'%(from)s-%(to)s relationships'
You can override automatically generated verbose_name and verbose_name_plural for the AdminInline that manages the many-to-many relation:
class CategoryInline(admin.TabularInline):
model = BaseProduct.categories.through
verbose_name = "Category item"
verbose_name_plural = "Category items"
For the unicode method definition, please see the answer with posted solutions for using proxy model and monkey patch the unicode method.
Django: Friendlier header for StackedInline for auto generated through model?
-
Thanks, this helped me, too. My concern was less that “relationship” was displayed, but that we have several many to many relationships to the same model (different kinds of addresses in this case), and unlike in the standard widget or the filter_horizontal or filter_vertical, the field names or their “verbose_name”s in the model, which are different of course, are not displayed, but only the class names. So we need a way to differentiate these relations. verbose_name and verbose_name_plural in the inline model solves this issue. – Jens-Erik Weber Jul 27 '16 at 15:37