I have the following Form:
class GuaranteesForm(forms.ModelForm):
birth_date = forms.DateField(input_formats=['%d/%m/%Y'], required=True)
However if the user inserts an invalid date like: 13/13/1999 instead of raising an exception, Django converts the date by performing modulus of the day and month fields, and adding months and years accodingly. In the example, since the month is above 12, the Date which would get persisted would be 13/01/2000.
I’d much rather get an InvalidFormException, is there any way to prevent this behaviour?
I’m using Django on Jython (DOJ).
I’ve already implemented a solution through clean_birth_date, but I think it’s rather ugly. What I’m looking for is a way to prevent this kind of behaviour with dates in general.
You can rise an exception manually when cleaning a specific form field.