Django:强制管理员用户在TabularInline中输入至少一个项目 [英] Django: Forcing admin users to enter at least one item in TabularInline
问题描述
在我的管理员对象主席
我有一个 TabularInline
任意数量的 Desk
对象。我希望每个椅子
总是至少有一个与它相关联的 Desk
对象。有没有办法使管理界面强制用户至少输入一个 Desk
?如果没有输入 Desk
,则显示错误。
In my admin for an object Chair
I have a TabularInline
for an arbitrary number of Desk
objects. I want every Chair
to always have at least one Desk
object associated with it. Is there a way to make the admin interface force the user to enter at least one Desk
? Like show an error if no Desk
is entered?
推荐答案
Matthew Flanagan有一个很好的例子,说明如何在一个表单集中要求一个有效的表单: http:// code。 google.com/p/wadofstuff/wiki/WadOfStuffDjangoForms 和 http://wadofstuff.blogspot.com/2009/08/requiring-at-least-one-inline-formset.html
希望能帮助你。
Matthew Flanagan has a great example of how to require one valid form in a formset: http://code.google.com/p/wadofstuff/wiki/WadOfStuffDjangoForms and http://wadofstuff.blogspot.com/2009/08/requiring-at-least-one-inline-formset.html Hope that helps you out.
这篇关于Django:强制管理员用户在TabularInline中输入至少一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!