user35288
user35288

Reputation:

Django Admin Inlines - Custom labels?

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?

Upvotes: 7

Views: 7461

Answers (1)

bmihelac
bmihelac

Reputation: 6323

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?

Upvotes: 16

Related Questions