I need to overwrite the clean() method in a Django Model form to perform additional uniqueness checks on the data entered.
This page gives implementation details: https://docs.djangoproject.com/en/1.11/ref/forms/validation/ Copied here:
def clean(self):
cleaned_data = super(ContactForm, self).clean()
cc_myself = cleaned_data.get("cc_myself")
subject = cleaned_data.get("subject")
if cc_myself and subject:
# Only do something if both fields are valid so far.
if "help" not in subject:
raise forms.ValidationError(
"Did not send for 'help' in the subject despite "
"CC'ing yourself."
)
However I'm confused why this method doesn't return cleaned_data at the end of the function? Surely that is the correct thing to do?