StreamField Deep Dive: How to find undocumented options
Writing a StreamField without a custom class
For simple StreamFields you do not need to create custom classes. If you want to, that's 100% OK to do. Below you will see an example of a
CharBlock that uses most of the available
from wagtail.core.fields import StreamField from wagtail.core.models import Page from wagtail.core import blocks as streamfield_blocks class FlexPage(Page): """Flexible page class.""" content = StreamField( [ ("char_block", streamfield_blocks.CharBlock( required=True, help_text="Oh wow this is help text!!", min_length=10, max_length=50, template="streams/char_block.html", )) ], null=True, blank=True, )
If you're wondering how I know we can use these fields:
Well the TL;DR version is: I went to the source code https://github.com/wagtail/wagtail/blob/master/wagtail/core/blocks/field_block.py#L97
If you want to know how I found this, you'll need to watch the video and about half way through I start talking about how to find the source code by working backwards from my current code.
The Git Commit
Take a look at all the code I wrote in this tutorial: https://github.com/CodingForEverybody/learn-wagtail/commit/261adec1f07a4fe74f53610b69418b5f52484240
Was this helpful to you?
Sharing is caring. Help the community by sharing this article.