wagtail-streamfield

Add StreamBlock child items programmatically in Wagtail

一世执手 提交于 2019-12-06 09:38:37
问题 I have the following StructBlock and StreamBlock below: class AccordionItemBlock(StructBlock): title = CharBlock() text = RichTextBlock() class AccordionRepeaterBlock(StreamBlock): accordion_item = AccordionItemBlock() I need to programmatically add it and multiple "item" CharBlocks to this page: class BasicPage(Page): body = StreamField([ ('accordion_repeater_block', AccordionRepeaterBlock()), ], null=True) This is how I am approaching it page.body = [ ( 'accordion_repeater_block', {

Add StreamBlock child items programmatically in Wagtail

血红的双手。 提交于 2019-12-04 15:10:55
I have the following StructBlock and StreamBlock below: class AccordionItemBlock(StructBlock): title = CharBlock() text = RichTextBlock() class AccordionRepeaterBlock(StreamBlock): accordion_item = AccordionItemBlock() I need to programmatically add it and multiple "item" CharBlocks to this page: class BasicPage(Page): body = StreamField([ ('accordion_repeater_block', AccordionRepeaterBlock()), ], null=True) This is how I am approaching it page.body = [ ( 'accordion_repeater_block', { 'accordion_item', { 'title': 'Title goes here', 'text': RichText('Testing!'), } } ) ] provider.save() I get