Implement Wagtail ListBlock module with min/max children

痴心易碎 提交于 2019-12-11 06:06:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!