This document details the block types provided by Wagtail for use in StreamField, and how they can be combined into new block types.
Changed in version 3.0: The required use_json_field argument is added.
body = StreamField([
('heading', blocks.CharBlock(form_classname="title")),
('paragraph', blocks.RichTextBlock()),
('image', ImageChooserBlock()),
], block_counts={
'heading': {'min_num': 1},
'image': {'max_num': 5},
}, use_json_field=True)
All block definitions accept the following optional keyword arguments:
default
label
ListBlock - the empty string).icon
wagtail.contrib.styleguide to your project’s INSTALLED_APPS.template
group
Since StreamField accepts an instance of StreamBlock as a parameter, in place of a list of block types, this makes it possible to re-use a common set of block types without repeating definitions:
class HomePage(Page):
carousel = StreamField(
CarouselBlock(max_num=10, block_counts={'video': {'max_num': 2}}),
use_json_field=True
)
StreamBlock accepts the following additional options as either keyword arguments or Meta properties:
body = StreamField([
# ...
('event_promotions', blocks.StreamBlock([
('hashtag', blocks.CharBlock()),
('post_date', blocks.DateBlock()),
], form_classname='event-promotions')),
], use_json_field=True)
class EventPromotionsBlock(blocks.StreamBlock):
hashtag = blocks.CharBlock()
post_date = blocks.DateBlock()
class Meta:
form_classname = 'event-promotions'
© 2014-present Torchbox Ltd and individual contributors.
All rights are reserved.
Licensed under the BSD License.
https://docs.wagtail.org/en/stable/reference/streamfield/blocks.html