[Django]-Django ModelForm not validating correctly with custom date format

4👍

In response to your comment above, the reason your first approach doesn’t work is that the format argument on the DateInput only controls the format in which this field’s initial value will be displayed. (from the docs).

It doesn’t control how submitted data is parsed – i.e., the DateField will still try to parse submitted data using its default formats. To change that you need the input_formats argument on the DateField (docs).

So really, you need to set both, as you did in your second attempt. The only problem there was a stray comma in your format.

If you are using consistent date formatting across your entire project, then you can just use the DATE_INPUT_FORMATS setting which will correctly configure both the DateField and the DateInput to use the same format. That way you don’t have to specify it individually.

Leave a comment