Django:需要所有formset表单? [英] Django: Make all formset forms required?
本文介绍了Django:需要所有formset表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如这个问题,除了没有真正答案的人已经关闭并被接受。看起来我可以使用自定义表单并覆盖干净的方法,但是仍然不能回答我如何检查它们是否全部填充。我应该看什么属性?
Exactly like this question, except that one got closed and accepted without a real answer. It looks like I can use a custom formset and override the clean method, but that still doesn't answer how I check that they're all filled in. What properties am I supposed to be looking at?
表单是聪明的,足以忽略未更改的额外表单。
The formset is smart enough to ignore extra forms that were not changed.
*尖叫*这使我无所畏惧。
*Screams* This has caused me nothing but agony.
推荐答案
想想我找到了解决方案通过挖掘源...
Think I found the solution by digging through the source...
class BaseVehicleFormSet(BaseFormSet):
def clean(self):
for i in range(self.total_form_count()):
if not self.forms[i].has_changed():
raise ValidationError("All vehicle forms must be filled in. Press \"remove\" if you've added too many.")
这篇关于Django:需要所有formset表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文