1👍
I think the problem might be in the clean() function.
Try accessing the fields using the cleaned_data dictionary:
def clean(self):
cleaned_data = super(JobQuickSearchForm, self).clean()
if cleaned_data['business_address_region'] and cleaned_data['business_industry'] and cleaned_data['keywords'] == '':
raise ValidationError("You must specify either email or telephone")
I would suggest checking the presence of ‘keywords’ key in the cleaned_data before comparing to the empty string.
if 'keywords' in cleaned_data ...
I did not test it, but you could give it a try :).
Alternatively you could skip the “super” call, and use self.cleaned_data as shown in the documentation.
Check with https://docs.djangoproject.com/en/1.9/ref/forms/validation/#cleaning-a-specific-field-attribute
0👍
I believe you’re looking for the cleaned data, which you should be able to access like this:
cleaned_data = super(JobQuickSearchForm, self).clean()
business_address_region = cleaned_data.get('business_address_region')
# etc.
See the example validation here: https://docs.djangoproject.com/en/1.9/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
- Custom Password Django Field for SSN?
- Django nginx + uwsgi [error] : *1 connect() failed (111: Connection refused) while connecting to upstream
- Django1.8.11 migrate installed_apps error
- ValueError at /new_topic/ Cannot assign "<SimpleLazyObject: <django……>": "Topic.owner" must be a "User" instance
Source:stackexchange.com