Exemple #1
0
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 = []
Exemple #2
0
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"),
    ]
Exemple #3
0
class JSONStreamModel(models.Model):
    body = StreamField(
        [
            ("text", CharBlock()),
            ("rich_text", RichTextBlock()),
            ("image", ImageChooserBlock()),
        ],
        use_json_field=True,
    )
Exemple #4
0
class JSONMinMaxCountStreamModel(models.Model):
    body = StreamField(
        [
            ("text", CharBlock()),
            ("rich_text", RichTextBlock()),
            ("image", ImageChooserBlock()),
        ],
        min_num=2,
        max_num=5,
        use_json_field=True,
    )
Exemple #5
0
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")]
Exemple #6
0
class DefaultStreamPage(Page):
    body = StreamField(
        [
            ("text", CharBlock()),
            ("rich_text", RichTextBlock()),
            ("image", ImageChooserBlock()),
        ],
        default="",
        use_json_field=False,
    )

    content_panels = [
        FieldPanel("title"),
        FieldPanel("body"),
    ]
Exemple #7
0
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,
    )
Exemple #8
0
class AddedStreamFieldWithEmptyListDefaultPage(Page):
    body = StreamField([("title", CharBlock())],
                       default=[],
                       use_json_field=False)
Exemple #9
0
class CaptionedPageLink(StructBlock):
    page = PageChooserBlock(required=False)
    text = CharBlock(max_length=250)