使用最小/最大孩子实现 Wagtail ListBlock 模块 [英] Implement Wagtail ListBlock module with min/max children

查看:23
本文介绍了使用最小/最大孩子实现 Wagtail ListBlock 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建用于 StreamField 的新块类型.它被称为 FAQModule,它应该允许一个标题和 1 个或多个问题/答案对.

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:

但是我想强制执行最小/最大数量的 Q/A 块.我看到 StreamBlock 允许这样做,但我和我的团队都同意 ListBlock 实现的接口正是我们想要的.因此,我正在努力根据 StreamBlock 实现.我在提交时出错,但我无法在内容"选项卡中显示徽章,也无法在块中显示错误.

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?

推荐答案

我暂时没有使用 StreamBlock,但 InlinePanel 有最小/最大项目关系的参数.

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

这篇关于使用最小/最大孩子实现 Wagtail ListBlock 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆