您好,我是初学wagtail和Django的人,在我的设计中,联系表位于主页上,只有我为初学者创建了教程,将联系表包括在专用的联系页中,以及如何在我的主页上包含联系表?
我的模型主页如下:
class HomePage(Page):
description = models.CharField(max_length=255, blank=True,)
content_panels = Page.content_panels + [ FieldPanel('description', classname="full") ]
在教程中,他们使用此模型:
class FormField(AbstractFormField):
page = ParentalKey('FormPage', related_name='custom_form_fields')
class FormPage(AbstractEmailForm):
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + [
InlinePanel('custom_form_fields', label="Form fields"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname="col6"),
FieldPanel('to_address', classname="col6"),
]),
FieldPanel('subject'),
], "Email Notification Config"),
]
def get_form_fields(self):
return self.custom_form_fields.all()
但是这会创建另一个我不需要的页面。如何在我的主页上添加表格?
非常感谢您。
答案 0 :(得分:2)
(未经测试),而不是本教程中的内容:
class FormField(AbstractFormField):
page = ParentalKey('FormPage', related_name='custom_form_fields')
这样做:
class FormField(AbstractFormField):
page = ParentalKey('HomePage', related_name='custom_form_fields')
,然后将HomePage
的定义更改为:
class HomePage(AbstractEmailForm, Page):
description = models.CharField(max_length=255, blank=True,)
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + Page.content_panels + [
FieldPanel('description', classname="full"),
InlinePanel('custom_form_fields', label="Form fields"),
FieldPanel('thank_you_text', classname="full"),
MultiFieldPanel([
FieldRowPanel([
FieldPanel('from_address', classname="col6"),
FieldPanel('to_address', classname="col6"),
]),
FieldPanel('subject'),
], "Email Notification Config"),
]
def get_form_fields(self):
return self.custom_form_fields.all()