在Wagtail中,假设我有一个这样的页面:
class MyPage(Page):
field_1 = RichTextField()
field_2 = models.DateField()
content_panels = Page.content_panels + [
FieldPanel('field_1'),
FieldPanel('field_2'),
]
我还有另一个与第一个模型有一对一关系的模型:
class PageSettings(models.Model):
page = models.OneToOneField(MyPage)
extra_setting_1 = models.BooleanField()
extra_setting_2 = models.CharField(max_length=50)
如何将PageSettings模型的表单添加到MyPage模型的Wagtail管理表单的底部?
通过一般关系来实现这一目标的方法的加分点。
答案 0 :(得分:1)
class MyPage(Page):
field_1 = RichTextField()
field_2 = models.DateField()
content_panels = Page.content_panels + [
FieldPanel('field_1'),
FieldPanel('field_2'),
InlinePanel('settings', label='Settings', min_num=1, max_num=1),
]
class PageSettings(models.Model):
page = ParentKey(MyPage, related_name='settings')
extra_setting_1 = models.BooleanField()
extra_setting_2 = models.CharField(max_length=50)