【发布时间】:2019-03-09 13:11:33
【问题描述】:
我是 Wagtail 的新手,想通过迭代这样的名称列表在我的 models.py 中创建几个字段 ...
class HomePage(Page):
myFields = [ ('paragraph', blocks.RichTextBlock(classname="oneA")),('image', ImageChooserBlock()) ]
mySections = ['sectionOne', 'sectionTwo', 'sectionThree']
for mySection in mySections:
mySection = StreamField(myFields,null=True,blank=True)
content_panels = Page.content_panels + [
StreamFieldPanel('sectionOne'), StreamFieldPanel('sectionTwo'), StreamFieldPanel('sectionThree'),
]
这会产生一条错误消息...
django.core.exceptions.FieldDoesNotExist:主页没有名为“sectionOne”的字段
有没有办法做到这一点,或者我必须像这样单独声明每个:
sectionOne = StreamField(myFields,null=True,blank=True)
【问题讨论】:
-
你也可以看看内联面板。 docs.wagtail.io/en/v2.0/reference/pages/…
标签: python-3.x wagtail