Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Supplying StreamField with default value in Wagtail admin interface

By default, wagtail's StreamField looks something like this in the admin for empty fields, showing the different blocks available for the user: Default view of a StreamField in the wagtail admin

I would however prefer it to contain a block of my choosing by default. For example:

A StreamField control with a single rich text block with content

How would I accomplish this? Setting a default keyword argument for the field didn't seem to work.

like image 215
cwj Avatar asked Mar 06 '19 10:03

cwj


1 Answers

When you tried to set a default keyword, did you set it on the RichTextBlock inside the StreamField? According to the docs, all block types accept the following optional keyword arguments: default, label, group, icon, and template. For example:

body = StreamField([
        ('paragraph', blocks.RichTextBlock(default='Add you content here')),
    ])
like image 177
cssidy Avatar answered Sep 26 '22 03:09

cssidy