let's say I have two models like below:
class Field1Stream(blocks.StreamBlock):
button1 = AnotherBlock(label="button main")
button2 = AnotherBlock(label="button secondary")
class Meta:
icon = "link"
required = False
block_counts = {
"button1": {"max_num": 1},
"button2": {"max_num": 1},
}
template = "my_template.html"
class NavBar(ClusterableModel, PreviewableMixin):
...
button = StreamField(
[("field1", Field1Stream()), ],
use_json_field=True, max_num=1
)
When I use Field1Stream
inside NavBar
model, it will create a nested structure. If I have a lot of Field1Stream()
then it is okay but here I have only one Field1Stream()
that's why I don't want to create a nested structure here.
With nested I mean like:
How can I avoid it?
When you pass a list to StreamField
, such as [("field1", Field1Stream()), ]
, it will implicitly turn that into a StreamBlock to use as the top-level of the stream. In this case, this results in a StreamBlock embedded in a StreamBlock. To avoid that, pass Field1Stream()
directly as the argument to StreamField
:
button = StreamField(
Field1Stream(),
use_json_field=True, max_num=1
)