rom*_*rom 13 django overriding modelform data-cleaning
关于模型的清理方法,我有两个问题.这是我的例子:
class AddProfileForm(ModelForm):
...
password = forms.CharField(max_length=30,widget=forms.PasswordInput(attrs={'class':'form2'}))
password_verify = forms.CharField(max_length=30,widget=forms.PasswordInput(attrs={'class':'form2'}), label='Retype password')
...
class Meta:
model = UserModel
fields=("username", "password", "password_verify", "first_name", "last_name", "date_of_birth", "biography", "contacts", )
#called on validation of the form
def clean(self):
#run the standard clean method first
cleaned_data=super(AddProfileForm, self).clean()
password = cleaned_data.get("password")
password_verify = cleaned_data.get("password_verify")
#check if passwords are entered and match
if password and password_verify and password==password_verify:
print "pwd ok"
else:
raise forms.ValidationError("Passwords do not match!")
#always return the cleaned data
return cleaned_data
Run Code Online (Sandbox Code Playgroud)
我应该一直打电话给标准清洁方法吗?
cleaned_data=super(AddProfileForm, self).clean()
Run Code Online (Sandbox Code Playgroud)我应该总是返回cleaning_data变量吗?
return cleaned_data
Run Code Online (Sandbox Code Playgroud) 归档时间: |
|
查看次数: |
16172 次 |
最近记录: |