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

不羁岁月 提交于 2019-11-28 07:31:46

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 admin
from models import Customer, Unit

class UnitInline(admin.TabularInline):
    model = Unit

class CustomerAdmin(admin.ModelAdmin):
    inlines = [
        UnitInline,
    ]
admin.site.register(Customer, CustomerAdmin)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!