表单集validate_min无法正常工作 [英] Formsets validate_min is not working properlly
问题描述
我有一个包含多个表单的表单集:
I have a formset with multiple forms:
PodFormSet = forms.inlineformset_factory(parent_model=PodP, model=Prod, form=PofModelForm, min_num=1, max_num=4,validate_min=True, extra=3)
问题在于validate_min无法正常工作:
The issues is that validate_min is not working properly:
如果用户填写的不是第一张表格,则validate_min无效,例如无效,这是无效的,因为至少填写了一张表格,但第一张表格却没有.
If the user complete another form than the first one, validate_min doesn't work, say is invalid, which is not, because at least a form is completed but not the first one.
如何覆盖/修复此行为?
How can I override/fix this behavior ?
推荐答案
根据我的记忆(如果我错了,请纠正我),Django中的表单集不够聪明,无法针对乱序表单进行验证.这意味着如果 min_num>验证期望索引( id )为0的形式存在.0
,您将不得不重新设置表单索引的格式.这通常是在前端完成的.
From what I remember (please correct me if I'm wrong) formsets in Django are not clever enough to validate against out-of-order forms. It means that
validation expects form with index (id) 0 to be present if min_num > 0
and you will have to re-format forms' indices. This is usually done on the front-end.
这篇关于表单集validate_min无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!