Reputation: 265
I want default date but in '%d-%m-%Y' format.
models.py
date = models.DateField(default=datetime.date.today)
what i have tried
forms.py
date = forms.DateField(input_formats='%d-%m-%Y')
Trying the above is not giving any default date in the form.
Upvotes: 1
Views: 10119
Reputation: 914
Your input formats should be a list:
date = forms.DateField(input_formats=['%d-%m-%Y'])
You can read more about this here
Upvotes: 0
Reputation: 2357
Use Format
method in your forms.py
:
date = forms.DateField(widget=DateInput(format='%d-%m-%Y'),
input_formats=['%d-%m-%Y'])
Upvotes: 0
Reputation: 3669
If you want to change default date format site wide, look at -
And in template, you can use a filter
-
{{you_date_field|date:'%d-%m-%Y'}}
Upvotes: 3