Scott
Scott

Reputation: 1353

how to change the django admin datepicker format?

I am using the admin's built-in datepicker, and I would like to change the default date format. In the DateTimeShortcuts.js file, it makes a call to format = get_format('DATE_INPUT_FORMATS')[0]; which gives it the default '%Y-%m-%d' format. It does not appear to use the DATE_INPUT_FORMATS values in the settings.py file, so there does not appear to be a way to change them. It also appears to be hard coded to the first one in the list.

If I step into the get_format statement, it takes me into this file in firebug:

/admin/jsi18n/
    inline

I am not a javascript wizard and I cannot find this file anywhere in the Django directory, so I don't know how to begin in overriding these values? Anyway in that file is the DATE_INPUT_FORMATS array with only 3 values, which doesn't match the DATE_INPUT_FORMATS in the settings.py file.

A last tidbit of info. I am using the datepicker by means of the AdminDateWidget in a custom field:

class PartialDateFormField(CharField):
    widget = AdminDateWidget

Any ideas or suggestions for changing the date format for this javascript datepicker?

Upvotes: 1

Views: 845

Answers (1)

mariodev
mariodev

Reputation: 15509

I18N is generating js translation files based on the FORMAT_MODULE_PATH. Please follow this section to see how to set up your own locale settings.

Here you can see how these settings look like for en locale, which is set by default. When you set your custom formats, admin will pick it up automatically.

Upvotes: 1

Related Questions