OK, trying to add a clean method to a ModelForm in Django. I’m adding a simple raise statement just to see if it works, and instead of my message, I get “Unidentified Errors. Please notify…”
Here’s my (simple) test:
class ConfigurationForm(forms.ModelForm):
...
def clean(self):
cleaned_data = self.cleaned_data
typeid = cleaned_data.get("typeid")
value = cleaned_data.get("value")
if value and typeid:
raise forms.ValidationError("this is the error")
I couldn’t even find a reference to “Unidentified Errors” anywhere in the django code base. Thanks in advance for your help.
Is your clean method returning the cleaned_data? If you look at the docs here:
https://docs.djangoproject.com/en/dev/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other
you’ll notice you have to make sure to return self.cleaned_data. Furthermore, don’t raise validation errors; instead delete the invalid field from the data (again, as you have to return it)
So: