假设有模型
class A(models.Model): name = models.CharField() class B(models.Model): name = models.CharField() a = models.ForeignKey(A)
如果想要在django admin 后台编辑A表记录时,能同时关联相应的B表记录,
class BAdmin(admin.ModelAdmin): list_display = ['a__name', ] class BInline(admin.StackedInline): model = B class AAdmin(admin.ModelAdmin): inlines = [BInline, ]