Django: Make all formset forms required?

妖精的绣舞 提交于 2019-12-22 08:51:14

问题


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.


回答1:


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.")


来源:https://stackoverflow.com/questions/3783519/django-make-all-formset-forms-required

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!