class StreamPage(Page): body = StreamField( [ ("text", CharBlock()), ("rich_text", RichTextBlock()), ("image", ExtendedImageChooserBlock()), ( "product", StructBlock([ ("name", CharBlock()), ("price", CharBlock()), ]), ), ("raw_html", RawHTMLBlock()), ( "books", StreamBlock([ ("title", CharBlock()), ("author", CharBlock()), ]), ), ], use_json_field=False, ) api_fields = ("body", ) content_panels = [ FieldPanel("title"), FieldPanel("body"), ] preview_modes = []
class DocumentPage(Page): date_published = models.DateField("Last Updated", blank=True, null=True) body = StreamField( [( "section", blocks.StreamBlock([ ("header", CharBlock()), ("text", blocks.RichTextBlock()), ("quote", BlockQuoteBlock()), ( "subsection", blocks.StreamBlock([ ("header", CharBlock()), ("text", blocks.TextBlock()), ( "subsubsection", blocks.StreamBlock([ ("header", CharBlock()), ("text", blocks.TextBlock()), ]), ), ]), ), ]), )], null=True, blank=True, use_json_field=True, ) content_panels = Page.content_panels + [ FieldPanel("date_published"), FieldPanel("body"), ]
class JSONStreamModel(models.Model): body = StreamField( [ ("text", CharBlock()), ("rich_text", RichTextBlock()), ("image", ImageChooserBlock()), ], use_json_field=True, )
class JSONMinMaxCountStreamModel(models.Model): body = StreamField( [ ("text", CharBlock()), ("rich_text", RichTextBlock()), ("image", ImageChooserBlock()), ], min_num=2, max_num=5, use_json_field=True, )
class InlineStreamPageSection(Orderable): page = ParentalKey("tests.InlineStreamPage", related_name="sections", on_delete=models.CASCADE) body = StreamField( [ ("text", CharBlock()), ("rich_text", RichTextBlock()), ("image", ImageChooserBlock()), ], use_json_field=False, ) panels = [FieldPanel("body")]
class DefaultStreamPage(Page): body = StreamField( [ ("text", CharBlock()), ("rich_text", RichTextBlock()), ("image", ImageChooserBlock()), ], default="", use_json_field=False, ) content_panels = [ FieldPanel("title"), FieldPanel("body"), ]
class JSONBlockCountsStreamModel(models.Model): body = StreamField( [ ("text", CharBlock()), ("rich_text", RichTextBlock()), ("image", ImageChooserBlock()), ], block_counts={ "text": { "min_num": 1 }, "rich_text": { "max_num": 1 }, "image": { "min_num": 1, "max_num": 1 }, }, use_json_field=True, )
class AddedStreamFieldWithEmptyListDefaultPage(Page): body = StreamField([("title", CharBlock())], default=[], use_json_field=False)
class CaptionedPageLink(StructBlock): page = PageChooserBlock(required=False) text = CharBlock(max_length=250)