jsindos
jsindos

Reputation: 539

Is it possible to limit a StreamField to accept exactly two blocks?

The title says it all, I haven't been able to find any other information online. I'm wondering if it is possible for me to get

secondary_links = StreamField([
    ('Page', SerialisedPageChooserBlock())])

to accept exactly two blocks.

Upvotes: 1

Views: 2384

Answers (1)

gasman
gasman

Reputation: 25317

Yes, this is possible as of Wagtail 1.12, with the min_num and max_num properties on StreamBlock:

secondary_links = StreamField(
    StreamBlock([
        ('Page', SerialisedPageChooserBlock())
    ], min_num=2, max_num=2)
)

Upvotes: 5

Related Questions