How can I make a Wagtail Streamfield not required?
Asked Answered
B

2

6

In the model below I want to make the bottom_content field in its entirety not required. How can I do this?

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')
  ]
Bipolar answered 16/11, 2017 at 18:37 Comment(0)
P
5

StreamField also accepts an optional keyword argument blank, defaulting to false; when this is false, at least one block must be provided for the field to be considered valid.

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

Puma answered 16/11, 2017 at 18:41 Comment(2)
this link is dead.Mulloy
docs.wagtail.org/en/latest/reference/streamfield/…Impoverish
R
2

The following works for me setting blank=True. Rollingers answer is a dead link so adding code example for anyone who needs it.

class BlogPage(Page):
    body = StreamField([
        ('heading', blocks.CharBlock(form_classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageChooserBlock()),
    ], blank=True)
Rumble answered 7/7, 2021 at 11:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.