I am new to Django and somewhat confused about the validation steps during form processing. I know that by default all types of form fields (in my case ModelForm) are required. I suggested that Django raise a VaidationError if the required form field is left blank without invoking a form cleanup method.
This is why I did not check if any data was installed in the following clean () method:
def clean(self): date = self.cleaned_data.get('date') time_start = self.cleaned_data.get('time_start') time_end = self.cleaned_data.get('time_end') user_type = self.cleaned_data.get('user_type') if Event.objects.filter(user_type=user_type, date=date, time_start__lt=time_start, time_end__gt=time_start).exclude(pk=self.instance.pk).count(): raise forms.ValidationError("Overlapping with another event.")
Submitting a form while leaving all fields blank causes
ValueError: cannot use None as the value of the request.
If I remove my clean () method, I get the expected ValidationErrors so that I donβt fill out the required fields - this is what I expected when the clean () method was still in place.
Any idea what might trigger this? I would be surprised if Django does not check the required values ββbefore it calls clean.
source share