I have a Page model with a StreamField:
from wagtail.core.fields import StreamField
from wagtail.embeds.blocks import EmbedBlock
class SomeModel(Page):
stream_field = StreamField(
[
("embed", EmbedBlock()),
]
)
I would like to create a new SomeModel
instance via code and populate the stream_field
with an embed value. E.g.
from wagtail.embeds.blocks import EmbedValue
some_model_instance = SomeModel()
embed_url = "https://youtube.com/something"
embed_value = EmbedValue(embed_url)
embed_block = ("embed", embed_value)
some_model_instance.stream_field.append(embed_block)
some_model_instance.save()
The above code pattern works without error, but when I view the content in the Wagtail Admin UI the field is empty (as if nothing was provided).
How can I add content to a Wagtail StreamField EmbedBlock via code?