【问题标题】:How can I make a Wagtail Streamfield not required?如何使 Wagtail Streamfield 不需要?
【发布时间】:2018-04-30 10:02:42
【问题描述】:

在下面的模型中,我想让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')
  ]

【问题讨论】:

    标签: django django-models wagtail wagtail-streamfield


    【解决方案1】:

    StreamField 也接受一个可选的关键字参数空白,默认为 false;如果为 false,则必须至少提供一个块才能将该字段视为有效。

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

    【讨论】:

    • 此链接已失效。
    【解决方案2】:

    以下设置blank=True对我有用。 Rollingers 的答案是一个死链接,因此为任何需要它的人添加代码示例。

    class BlogPage(Page):
        body = StreamField([
            ('heading', blocks.CharBlock(form_classname="full title")),
            ('paragraph', blocks.RichTextBlock()),
            ('image', ImageChooserBlock()),
        ], blank=True)
    

    【讨论】:

      猜你喜欢
      • 2016-10-29
      • 1970-01-01
      • 2016-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多