In Django, I have a form class with a clean function. In this clean function, I check to see if an optional select box was filled out.
def clean_session_1(self):
# Check if session_1 is filled out.
if self.cleaned_data['session_1']:
# more validation
return self.cleaned_data['session_1']
If the select box was filled out, then more validation of the field ensues.
For some reason, this code is not testing whether the field was filled out and runs “more validation” every time.
I was wondering how can one reliably test if this field “session_1” was filled out? Thanks!
Access
self._raw_value('key')to get the raw entry in the form field (i.e. just text, not processed to a python object).Update: As Ahsan says, do it in the
cleanmethod. You should probably call the superclass clean method also.