Tutorial Summary

In this video we are going to learn how to create a RichTextBlock StreamField, and then we're going to duplicate that StreamField and limit the number of features the editor gives us.

Note: This is a 2 part video lesson. Part 1 will covered how to create a basic StreamField from scratch.

In this video we are going to explore how to add a RichTextBlock as a StreamField inside of an app called "streams". There are a number of ways to add a RichText StreamField to your pages, and we're covering a couple of the harder methods in this video.

# streams/blocks.py
from wagtail.core import blocks


class RichtextBlock(blocks.RichTextBlock):
    """Richtext with all the features."""

    class Meta:  # noqa
        template = "streams/richtext_block.html"
        icon = "doc-full"
        label = "Full RichText"


class SimpleRichtextBlock(blocks.RichTextBlock):
    """Richtext without (limited) all the features."""

    def __init__(
        self, required=True, help_text=None, editor="default", features=None, **kwargs
    ):  # noqa
        super().__init__(**kwargs)
        self.features = ["bold", "italic", "link"]

    class Meta:  # noqa
        template = "streams/richtext_block.html"
        icon = "edit"
        label = "Simple RichText"
# flex/models.py
# .....
from streams import blocks.py

class FlexPage(Page):
    # ....

    content = StreamField(
        [
            ("title_and_text", blocks.TitleAndTextBlock()),
            ("full_richtext", blocks.RichtextBlock()),
            ("simple_richtext", blocks.SimpleRichtextBlock()),
        ],
        null=True,
        blank=True,
    )
The Git Commit

If you're interested in seeing the entire commit for this video, all the source code is available here.

Sign up for our newsletter

Get notified about new lessons :)


Our Sites