如何在Wagtail中为StructBlock分配编辑面板?

时间:2019-12-17 13:44:38

标签: wagtail wagtail-streamfield

我有一个这样的StructBlock:

class JumbotronBlock(blocks.StructBlock):
fullwidth= blocks.BooleanBlock(requried=False, help_text="Full width of the viewport")
heading= blocks.CharBlock(required=True, help_text="Heading for the jumbotron")
lead= blocks.CharBlock(required= False, help_text= "Lead text for Jumbotron")
link= LinkBlock(required=False)
bg_image= ImageChooserBlock(required=False)
bg_color= blocks.CharBlock(required=False, help_text="Hex value for background color")
classes= blocks.CharBlock(required=False, help_text="CSS classes for jumbotron")
styles= blocks.CharBlock(required=False, help_text="Custom style definitions for jumbotron")

class Meta:
    template="streams/jumbotron_block.html"
    icon= "placeholder"
    label= "Jumbotron"

我的HomePage Class模型是这样的:

class HomePage(Page):
template= "home/home_page.html"
header= Jumbotron()

body =  StreamField([
    ('Richtext', RichTextBlock()),
    ('CTA', CTABlock()),
    ('Section', SectionBlock()),
    ])

content_panels = Page.content_panels + [
    ??which panel here??('header'),
    StreamFieldPanel('body'),
    ]

我应该使用哪个面板将Jumbotron添加到编辑面板?谢谢。

1 个答案:

答案 0 :(得分:2)

StructBlock不能用作模型字段-仅在StreamField内部有效。您需要在HomePage模型中将巨型波块的字段定义为Django model fields,并且-如果要在编辑视图中将它们可视地分组在一起,请将它们放在MultiFieldPanel中。