问题
I'm building a new block type for use in the StreamField. It's called an FAQModule and it should allow a title and 1 or more question/answer pairs.
class FAQBlock(blocks.StructBlock):
headline = blocks.TextBlock(help_text="Enter headline / question")
text = blocks.TextBlock(help_text="Enter a description / answer ")
class FAQCardsWithListBlock(blocks.StructBlock):
title = blocks.TextBlock(help_text="Enter FAQ title")
questions = blocks.ListBlock(FAQBlock())
class Meta:
label = 'FAQ Block'
icon = 'help'
It works exactly as expected, and looks like this:
However I want to enforce a min/max number of Q/A blocks. I see that the StreamBlock allows for this but my team and I agree that the interface for the ListBlock implementation is exactly what we want. So I'm working to add a min/max enforcement to our feature based off what's in the StreamBlock implementation. I've gotten it to error on submit, but I can't get the badge to show up in the Content tab, nor can I get the error to show itself in the block.
Does anyone have thoughts on how this might be accomplished?
回答1:
i don't have use StreamBlock for the moment, but the InlinePanel have parameters for minimum / maximum item relation.
http://docs.wagtail.io/en/v2.0/reference/pages/panels.html#inlinepanel
来源:https://stackoverflow.com/questions/58204856/implement-wagtail-listblock-module-with-min-max-children