我的Django的模型如下:添加几个对象在Django管理
class Page(models.Model):
title = models.CharField(max_length=200)
class Section(models.Model):
page_id = models.ForeignKey(Page)
title = models.CharField(max_length=200)
class SubSection(models.Model):
section_id = models.ForeignKey(Section)
title = models.CharField(max_length=200)
而且我想在Django管理添加新Page
与可能性增加几个Section
中,我可以添加多个SubSection
。
我已经成功创建一个页面,我们可以添加一个Page
中,我们可以添加多个Section
,但它要求只为Section
的名字,有没有可能在同一页中添加SubSection
。
我尝试这样做:
class SectionInline(admin.TabularInline):
model = Section
extra = 3
class PageAdmin(admin.ModelAdmin):
inlines = [SectionInline]
admin.site.register(Page, PageAdmin)
但我不能添加到SubSectionInline
SectionInline
。
有没有办法做到这一点?
谢谢。