如何使用该clean
方法更改 Django 表单集的每种表单中的字段?
class MyInlineFormSet(BaseInlineFormSet):
def clean(self):
if self.cleaned_data['inputted'] == self.cleaned_data['answer']:
self.cleaned_data['is_correct'] = True
return self.cleaned_data
这是行不通的,我看到人们迭代每个表单,但他们只验证而不改变。如果我遍历每个表单,我该如何返回cleaned_data
?换句话说:
class MyInlineFormSet(BaseInlineFormSet):
def clean(self):
for form in self.forms:
if form.cleaned_data['inputted'] == form.cleaned_data['answer']:
form.cleaned_data['is_correct'] = True
...?