jayt jayt -4 years ago 62
Python Question

Django - Formatting of date to update a model object from forms

I've got a form which will be populated with any data from a saved model object so that the object can be updated. However the date field seems to be pre-populated with a date like...

2016-09-07 00:00:00+00:00


I want this to be in the format 'mm dd YYYY'.

In my HTML template I've tried
{{ form.date_start|date:'m d Y' }}
which doesn't raise an error but just removes the input field altogether.

Any ideas on how to specify a date format to pre-populate a date field with?

Thanks!

Answer Source

try putting this in your forms

date_start = forms.DateField(input_formats=['%d-%m-%y'],widget=forms.Date‌​Input(format = '%d-%m-%y'))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download