如何使 Wagtail Streamfield 不再需要?

NVN*_*NVN 6 django django-models wagtail wagtail-streamfield

在下面的模型中,我想让bottom_content整个字段不再是必需的。我怎样才能做到这一点?

class ServicePage(Page):
  top_content = StreamField(default_blocks + [
    ('two_columns', TwoColumnBlock()),
    ('three_columns', ThreeColumnBlock()),
  ])
  bottom_content = StreamField(default_blocks + [
    ('two_columns', TwoColumnBlock()),
    ('three_columns', ThreeColumnBlock()),
  ])

  search_fields = Page.search_fields + [
    index.SearchField('top_content'),
    index.SearchField('bottom_content'),
  ]

  content_panels = Page.content_panels + [
    StreamFieldPanel('top_content'),
    StreamFieldPanel('bottom_content'),
    InlinePanel('service_package', label='Packages')
  ]
Run Code Online (Sandbox Code Playgroud)

rol*_*ger 5

StreamField还接受可选关键字参数blank,默认为false;当此值为 false 时,必须至少提供一个块才能使该字段被视为有效。

来自: - http://docs.wagtail.io/en/latest/topics/streamfield.html

  • 这个链接已经死了。 (2认同)