如何限制 django admin 内联表单集 [英] how to limit django admin inline formsets

查看:31
本文介绍了如何限制 django admin 内联表单集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 django admin 中如何限制内联表单集?

How do you limit the inline formset in django admin?

问题:

我有一个表 A,与 B 有 1 到 n 的关系.表 A 应该至少有一个表 B 项目和最多 5 个表 B 项目.

I have a table A with 1 to n relationship with B. Table A should have at least one Table B item and a max of 5 Table B items.

推荐答案

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-options

Inline 定义中指定 max_num 以限制数量.

Specify max_num in your Inline definition to limit the number.

extra 指定要显示多少个空白行.

extra specifies how many blank inlines to show.

需要 1 内联吗?如果表 B 未填充至少 1 行,您想触发验证错误吗?

Is the 1 inline required? As in you want to trigger a validation error if table B isn't filled with at least 1 row?

这篇关于如何限制 django admin 内联表单集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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