Skip to content

Instantly share code, notes, and snippets.

@mwesterhof
Created September 10, 2019 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwesterhof/85aaaaa4978f5187f567ad946ae36487 to your computer and use it in GitHub Desktop.
Save mwesterhof/85aaaaa4978f5187f567ad946ae36487 to your computer and use it in GitHub Desktop.
nested blocks, to reproduce validation issue for wagtail_react_streamfield
# home/blocks.py
from wagtail.core import blocks
from wagtail.images.blocks import ImageChooserBlock
class SomeImageBlock(blocks.StructBlock):
title = blocks.CharBlock()
image = ImageChooserBlock()
class Meta:
template = 'home/blocks/some_image_block.html'
class SomeParagraphBlock(blocks.StructBlock):
title = blocks.CharBlock()
text = blocks.CharBlock()
class Meta:
template = 'home/blocks/some_paragraph_block.html'
class SomeContainerBlock(blocks.StructBlock):
title = blocks.CharBlock()
content = blocks.StreamBlock([
('image', SomeImageBlock()),
('paragraph', SomeParagraphBlock()),
])
class Meta:
template = 'home/blocks/some_container_block.html'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment