django custom validation - reference submitted form value -
i trying django custom validate form field.
i have written code below, cannot think of how reference submitted value of employment_record_date_display_type included in employmentrecordform.
i tried employment_record_date_display_type = employmentrecordform.employment_record_date_display_type gives following error:
type object 'employmentrecordform' has no attribute 'employment_record_date_display_type'
here validation code in forms.py file:
class employmentrecordform(forms.modelform): ............. def clean_employment_record_completion_date(self): employment_record_display_type = self.cleaned_data.get('employment_record_display_type') employment_record_date_display_type = ????????? employment_record_commencement_date = self.cleaned_data.get('employment_record_commencement_date') employment_record_completion_date = self.cleaned_data.get('employment_record_completion_date') if employment_record_display_type == 0: if employment_record_completion_date not none , employment_record_commencement_date not none: if employment_record_commencement_date > employment_record_completion_date: if employment_record_date_display_type == 2 or employment_record_date_display_type == 3: raise forms.validationerror(_("to date must greater date.")) elif employment_record_date_display_type == 4 or employment_record_date_display_type == 5: raise forms.validationerror(_("finish date must greater start date.")) elif employment_record_date_display_type == 6 or employment_record_date_display_type == 7: raise forms.validationerror(_("end date must greater begin date.")) elif employment_record_date_display_type == 8 or employment_record_date_display_type == 9: raise forms.validationerror(_("this date must greater other date.")) else: raise forms.validationerror(_("completion date must after commencement date.")) return employment_record_completion_date
how reference submitted value of employment_record_date_display_type ?
you should write custom validator class , in fields want should have validators list property. this:
price = models.integerfield(validators=[mycustomvalidator])
Comments
Post a Comment