How to I show a list of ForeignKey reverse lookups in the DJango admin interface? How to I show a list of ForeignKey reverse lookups in the DJango admin interface? django django

How to I show a list of ForeignKey reverse lookups in the DJango admin interface?


By default, a ModelAdmin will only let you manage the model "itself", not related models. In order to edit the related Unit model, you need to define an "InlineModelAdmin" - such as admin.TabularInline - and attach it to your CustomerAdmin.

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

For example, in your admin.py:

from django.contrib import adminfrom models import Customer, Unitclass UnitInline(admin.TabularInline):    model = Unitclass CustomerAdmin(admin.ModelAdmin):    inlines = [        UnitInline,    ]admin.site.register(Customer, CustomerAdmin)