假设有模型
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, ]
原文地址:https://www.cnblogs.com/linyihai/p/10199893.html
时间: 2024-10-11 04:55:28