Hi Caroline,
Unfortunately putting a StreamField inside an inline child object isn't something we've tested or are able to support right now. As far as I know there's no fundamental reason why it *couldn't* be made to work, but it involves some complicated interactions between different components of Wagtail - both server-side, and in the Javascript that powers the edit interface - so I wouldn't be at all surprised to find some bugs lurking in there.
One thing that does work - although the UI for it will be rather ugly - is nesting a StreamField (or rather, a StreamBlock) within a StreamField. You could have a 'chapters' StreamField as a field of ChapteredArticlePage, where the only available block type is BodyBlock, a StreamBlock with all of your block types. In other words, you're using an outer StreamField as the repeating mechanism, rather than an inline model:
# a refactored version of your BodyField, which makes the underlying StreamBlock available to be re-used:
class BodyBlock(blocks.StreamBlock):
Heading = HeadingBlock()
Paragraph = ParagraphBlock()
Image = ImageBlock()
Embed = EmbedBlock(icon="site")
List = blocks.ListBlock(blocks.RichTextBlock(label="item"), icon="list-ul")
class BodyField(StreamField):
def __init__(self, **kwargs):
super(BodyField, self).__init__(BodyBlock(), **kwargs)
class ChapteredArticlePage(Page):
excerpt = RichTextField(blank=True, default="")
body = BodyField()
# a StreamField where the only available block is BodyBlock
chapters = StreamField([
('Chapter', BodyBlock()),
])
ChapteredArticlePage.content_panels = Page.content_panels + [
FieldPanel('excerpt'),
StreamFieldPanel('body'),
StreamFieldPanel('chapters'),
]
(incidentally, I'd recommend using lower-cased names for your block identifiers - 'heading', 'paragraph' etc - as those are the equivalent of model field names, and will be capitalised automatically when they appear as labels in the admin. I've kept them capitalised here for consistency.)
Once your page model reaches this level of complexity, though, I'd be more inclined to look for ways of breaking down the content into smaller individually-editable units. Perhaps Chapter could be a page type of its own, which you create as a subpage of ChapteredArticlePage? That doesn't necessarily mean that it has to be presented as multiple pages on the front-end - the subpages would just be containers for the page data, and the parent ChapteredArticlePage would retrieve that (as an index page would) and output the complete article.
Cheers,
- Matt
> --
> You received this message because you are subscribed to the Google Groups "Wagtail support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
wagtail+u...@googlegroups.com.
> To post to this group, send email to
wag...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/wagtail.
> To view this discussion on the web, visit
https://groups.google.com/d/msgid/wagtail/7fd950bf-86f6-4575-9cb6-2fde7bc85c9f%40googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.