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')
  ]
NVN
  • 147
  • 2
  • 7

2 Answers2

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

Bharathwaaj
  • 2,627
  • 2
  • 22
  • 35
rollinger
  • 531
  • 1
  • 4
  • 15
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)
Aidan Doherty
  • 962
  • 2
  • 11
  • 29