我想向Wagtail表单生成器添加一个新的表单字段,以创建文件上传字段。 https://stackoverflow.com/a/47932918/2074077有一个相关的问题,一个可以接受的答案,但这是针对Wagtail的旧版本。
如何将文件上载字段添加到Wagtail 2(或更新的)表单生成器中?
这是我的代码,但是我不确定在哪里可以将“文件上载”字段集成为一个选项。
from modelcluster.fields import ParentalKey
from wagtail.admin.edit_handlers import (
FieldPanel, FieldRowPanel,
InlinePanel, MultiFieldPanel
)
from wagtail.core.fields import RichTextField
from wagtail.contrib.forms.models import AbstractEmailForm,
AbstractFormField
class FormField(AbstractFormField):
page = ParentalKey('FormPage', on_delete=models.CASCADE,
related_name='custom_form_fields')
class FormPage(AbstractEmailForm):
intro = RichTextField(blank=True)
thank_you_text = RichTextField(blank=True)
content_panels = AbstractEmailForm.content_panels + [
FieldPanel('intro', 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"),
]
def get_form_fields(self):
return self.custom_form_fields.all()