Date formats and Django forms
December 13th, 2009
Date formats are something that US dominance remains unable to overcome. Whilst all software assumes a format of mm/dd/yyyy, all other nations of the world want to change that to their local preference.
Django is no exception.
Here’s the magic incantation to make Django 1.1 output and input dates in an Australian format.
DATE_FORMAT = '%d/%m/%Y'
...
class ProfileForm(forms.ModelForm):
...
date_of_birth = forms.DateField()
date_of_birth.widget = forms.DateInput(format=DATE_FORMAT)
date_of_birth.input_formats = (DATE_FORMAT,)
John is a freelance programmer living in Sydney Australia. He blogs whatever takes his fancy; computing tips, travel letters, and random stuff from his life. He does it primarily to learn and demonstrate the running of a website.
Recent Comments