我正在寻找一些关于如何对表单集进行自定义验证的建议。
这就是我现在所拥有的,它返回以下我不完全知道如何处理的错误。
Exception Value:
'MilestoneFormFormSet' object has no attribute 'save'
表格.py
class BaseMilestoneFormSet(BaseFormSet):
def clean(self):
for form in self.forms:
data = form.cleaned_data
target_date = data["target_date"]
project = data["project"]
if target_date > project.target_date:
raise forms.ValidationError("Target Date is outside of project target date")
return data
MilestoneFormSetNew = modelformset_factory(Milestone, formset=BaseMilestoneFormSet, max_num=50, extra=1)
Views.py 摘录
if request.method == 'POST': # Loop through the submitted formsets check for erros and save the data.
formsetNew = MilestoneFormSetNew(request.POST, prefix='new')
if formsetNew.is_valid():
formsetNew.save()
return HttpResponseRedirect(reverse('pooflinger.project.views.detail', args=(project.id,)))