内联直接关系很容易,但是如何为更深层次的关系创建内联?
让我们说情况就像
class A(models.Model):
...
class B(models.Model):
a = models.ForeignKey(A)
class C(models.Model):
b = models.ForeignKey(B)
现在我想要的是A
的内联管理员,它会显示所有C
个B
的{{1}}名称。我该怎么做?
答案 0 :(得分:4)
看看django-nested-inlines。例如:
from django.contrib import admin
from nested_inlines.admin import NestedModelAdmin, NestedStackedInline, NestedTabularInline
from models import A, B, C
class MyNestedInline(NestedTabularInline):
model = C
class MyInline(NestedStackedInline):
model = B
inlines = [MyNestedInline,]
class MyAdmin(NestedModelAdmin):
pass
admin.site.register(A, MyAdmin)