I have a page with one StreamField body and a custom block named HeadingBlock:
class HeadingBlock(blocks.StructBlock):
heading = blocks.CharBlock()
cssid = blocks.CharBlock()
...
class CustomPage(Page):
...
body = StreamField([
('heading', HeadingBlock()),
...
I need to add new charblock to heading attribute of HeadingBlock, but using shell:
>>> from custom.models import CustomPage
>>> c = CustomPage.objects.all()[0]
>>> c.body[0].heading.value = "hello world" ??? this does not work
Anyone can help? thanks a lot!
EDIT: I simplified the HeadingBlock, removing ListBlock and tried:
>>> c.body[0].value
StructValue([('heading', u'hi'), ('cssid', u'man')])
>>> type(c.body[0].value)
<class 'wagtail.wagtailcore.blocks.struct_block.StructValue'>
>>> from wagtail.wagtailcore.blocks.struct_block import StructValue
>>> c.body[0].value = StructValue([('heading', u'hello'), ('cssid', u'world')])
>>> c.save()
but when i go in admin interface, the fields are empty. I tried:
>>> c.body[0].block.child_blocks
OrderedDict([('heading', <wagtail.wagtailcore.blocks.field_block.CharBlock object at 0x7f4c2aaf9790>), ('cssid', <wagtail.wagtailcore.blocks.field_block.CharBlock object at 0x7f4c2aaf9a90>)])
>>> c.body[0].block.child_blocks['heading']
<wagtail.wagtailcore.blocks.field_block.CharBlock object at 0x7f4c2aaf9790>
>>> c.body[0].block.child_blocks['heading'].value
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'CharBlock' object has no attribute 'value'
Nothing happen, i do not think this is so difficult :-|