Skip to content

Commit

Permalink
Wagtail 6.0 upgrade consideration: StreamField no longer requires use…
Browse files Browse the repository at this point in the history
…_json_field=True
  • Loading branch information
katdom13 committed Feb 16, 2024
1 parent d03ca08 commit 7ab3a7b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tests/testapp/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from wagtail import blocks
from wagtail import blocks, VERSION as WAGTAIL_VERSION
from wagtail.documents.blocks import DocumentChooserBlock
from wagtail.fields import StreamField
from wagtail.images.blocks import ImageChooserBlock
from wagtail.models import Page

# Wagtail 6.0 upgrade consideration
# StreamField no longer requires use_json_field=True
extra_args = {"use_json_field": True} if WAGTAIL_VERSION >= (6, 0) else {} # type: ignore


class MyBlockItem(blocks.StructBlock):
label = blocks.CharBlock()
Expand All @@ -29,7 +33,7 @@ class SimpleStructBlockNestedStream(blocks.StreamBlock):


class PageWithSimpleStructBlockNested(Page):
body = StreamField(SimpleStructBlockNestedStream(), use_json_field=True)
body = StreamField(SimpleStructBlockNestedStream(), **extra_args,)


class MyTestPage(Page):
Expand All @@ -42,7 +46,7 @@ class MyTestPage(Page):
("image", ImageChooserBlock()),
("document", DocumentChooserBlock()),
],
use_json_field=True,
**extra_args,
)


Expand All @@ -68,16 +72,16 @@ class DeeplyNestedStreamBlockInListBlock(blocks.StreamBlock):


class PageWithStreamBlock(Page):
body = StreamField(MyStreamBlock(), use_json_field=True)
body = StreamField(MyStreamBlock(), **extra_args,)


class PageWithNestedStreamBlock(Page):
body = StreamField(NestedStreamBlock(), use_json_field=True)
body = StreamField(NestedStreamBlock(), **extra_args,)


class PageWithStreamBlockInStructBlock(Page):
body = StreamField(DeeplyNestedStreamBlock(), use_json_field=True)
body = StreamField(DeeplyNestedStreamBlock(), **extra_args,)


class PageWithStreamBlockInListBlock(Page):
body = StreamField(DeeplyNestedStreamBlockInListBlock(), use_json_field=True)
body = StreamField(DeeplyNestedStreamBlockInListBlock(), **extra_args,)

0 comments on commit 7ab3a7b

Please sign in to comment.