django admin后台中如何处理外键显示?


如:


 class A(models.Model):
        name = models.CharField()

    class B(models.Model):
        name = models.CharField()
        a    = models.ForeignKey(A)

当在admin中注册A,B后,如果想要显示所有A中的b_set内容,该如何定制admin?

谢谢!

python web django

糟糕的狐狸 9 years, 12 months ago

 
class BAdmin(admin.ModelAdmin): list_display = ['a__name', ]


 class BInline(admin.StackedInline):
    model = B


class AAdmin(admin.ModelAdmin):
    inlines = [BInline, ]

第一排抱树 answered 9 years, 12 months ago

Your Answer