我想在我的表单文件的干净方法中重新定义字段的必需属性:
class NewUserFullForm(NewUserForm):
REGEX_PHONE = '^(\+[0-9]{2})[ \.\-]?[0-9][ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}[ \.\-]?[0-9]{2}$'
phone = forms.RegexField(REGEX_PHONE, help_text='Ex : +33 1 34 12 52 30')
fax = forms.RegexField(REGEX_PHONE, help_text='Ex : +33 1 34 12 52 30', required=False)
gsm = forms.RegexField(REGEX_PHONE, help_text='Ex : +33 6 34 12 52 30', required=False)
def clean(self):
if self.cleaned_data["asso_waldec"] == True:
self.fields['phone'].required = True
但是我的干净方法不起作用