在 django 中,我从视图中调用了一个表单,它传递了一个在表单 init 中弹出的额外对象。我想在 init 之外的 clean def 中使用这个对象数据(人)。如何修复此传递信息的范围?谢谢!
class RegForm(forms.Form):
first = forms.CharField(min_length=5)
def __init__(self, *args, **kwargs):
person = kwargs.pop("person")
super(CompleteRegistrationForm, self).__init__(*args, **kwargs)
def clean_first(self):
if not self.cleaned_data['first'] == person.first:
raise forms.ValidationError(_("This information does not match records."))
else:
return self.cleaned_data['first']