Last Updated: February 25, 2016
·
3.115K
· Lorin Hochstein

Rename many-to-many label in admin interface

Here's how you can change the label for a tabular inline in the Django admin interface, which shows a many-to-many relationship. Let's say you have a relationship between products and accounts:

class Product(models.Model):
    ...
    accounts = models.ManyToManyField(Account)

To give this relationship a custom label when defining the admin interface:

class ProductsInline(admin.TabularInline):
    model = Product.accounts.through
    model._meta.verbose_name_plural = "Custom name here"

class AccountAdmin(admin.ModelAdmin):
    inlines = [ProductsInline]