kopia lustrzana https://github.com/wagtail/wagtail
Add StreamField context to block examples
rodzic
9f084fff6d
commit
3e2c928e2f
|
@ -373,12 +373,15 @@ Structural block types
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
('person', blocks.StructBlock([
|
body = StreamField([
|
||||||
('first_name', blocks.CharBlock()),
|
# ...
|
||||||
('surname', blocks.CharBlock()),
|
('person', blocks.StructBlock([
|
||||||
('photo', ImageChooserBlock(required=False)),
|
('first_name', blocks.CharBlock()),
|
||||||
('biography', blocks.RichTextBlock()),
|
('surname', blocks.CharBlock()),
|
||||||
], icon='user'))
|
('photo', ImageChooserBlock(required=False)),
|
||||||
|
('biography', blocks.RichTextBlock()),
|
||||||
|
], icon='user')),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
Alternatively, StructBlock can be subclassed to specify a reusable set of sub-blocks:
|
Alternatively, StructBlock can be subclassed to specify a reusable set of sub-blocks:
|
||||||
|
@ -421,17 +424,23 @@ Structural block types
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
('ingredients_list', blocks.ListBlock(blocks.CharBlock(label="Ingredient")))
|
body = StreamField([
|
||||||
|
# ...
|
||||||
|
('ingredients_list', blocks.ListBlock(blocks.CharBlock(label="Ingredient"))),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
Any block type is valid as the sub-block type, including structural types:
|
Any block type is valid as the sub-block type, including structural types:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
('ingredients_list', blocks.ListBlock(blocks.StructBlock([
|
body = StreamField([
|
||||||
('ingredient', blocks.CharBlock()),
|
# ...
|
||||||
('amount', blocks.CharBlock(required=False)),
|
('ingredients_list', blocks.ListBlock(blocks.StructBlock([
|
||||||
])))
|
('ingredient', blocks.CharBlock()),
|
||||||
|
('amount', blocks.CharBlock(required=False)),
|
||||||
|
]))),
|
||||||
|
])
|
||||||
|
|
||||||
The following additional option is available as either a keyword argument or a Meta class attribute:
|
The following additional option is available as either a keyword argument or a Meta class attribute:
|
||||||
|
|
||||||
|
@ -444,17 +453,20 @@ Structural block types
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
('carousel', blocks.StreamBlock(
|
body = StreamField([
|
||||||
[
|
# ...
|
||||||
('image', ImageChooserBlock()),
|
('carousel', blocks.StreamBlock(
|
||||||
('quotation', blocks.StructBlock([
|
[
|
||||||
('text', blocks.TextBlock()),
|
('image', ImageChooserBlock()),
|
||||||
('author', blocks.CharBlock()),
|
('quotation', blocks.StructBlock([
|
||||||
])),
|
('text', blocks.TextBlock()),
|
||||||
('video', EmbedBlock()),
|
('author', blocks.CharBlock()),
|
||||||
],
|
])),
|
||||||
icon='cogs'
|
('video', EmbedBlock()),
|
||||||
))
|
],
|
||||||
|
icon='cogs'
|
||||||
|
)),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
As with StructBlock, the list of sub-blocks can also be provided as a subclass of StreamBlock:
|
As with StructBlock, the list of sub-blocks can also be provided as a subclass of StreamBlock:
|
||||||
|
@ -490,12 +502,15 @@ Structural block types
|
||||||
:param form_classname: An HTML ``class`` attribute to set on the root element of this block as displayed in the editing interface.
|
:param form_classname: An HTML ``class`` attribute to set on the root element of this block as displayed in the editing interface.
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:emphasize-lines: 4
|
:emphasize-lines: 6
|
||||||
|
|
||||||
('event_promotions', blocks.StreamBlock([
|
body = StreamField([
|
||||||
('hashtag', blocks.CharBlock()),
|
# ...
|
||||||
('post_date', blocks.DateBlock()),
|
('event_promotions', blocks.StreamBlock([
|
||||||
], form_classname='event-promotions'))
|
('hashtag', blocks.CharBlock()),
|
||||||
|
('post_date', blocks.DateBlock()),
|
||||||
|
], form_classname='event-promotions')),
|
||||||
|
])
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
:emphasize-lines: 6
|
:emphasize-lines: 6
|
||||||
|
|
Ładowanie…
Reference in New Issue