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,)
  1. No comments yet.
  1. No trackbacks yet.