Django管理员显示本地化的日期格式 [英] Django admin to display localised date format
问题描述
我住在新西兰,日期格式为DD / MM / YYYY,但管理员中的日期字段显示YYYY-MM-DD,我已尝试通过以下方式更改小部件:
I live in New Zealand and the date format is DD/MM/YYYY, however the date field in admin shows YYYY-MM-DD, I have tried changing the widget by:
formfield_overrides = {
models.DateField: {'widget': widgets.DateInput},
}
自从文档:
DateInput
class DateInput
Date input as a simple text box: <input type='text' ...>
Takes same arguments as TextInput, with one more optional argument:
format
The format in which this field’s initial value will be displayed.
If no format argument is provided, the default format is the first format found in DATE_INPUT_FORMATS and respects Format localization.
另外在我的设置中:
USE_I18N = True
TIME_ZONE = 'Pacific/Auckland'
LANGUAGE_CODE = 'en-NZ' # or en-nz? both don't work
DATE_INPUT_FORMATS = ('%d/%m/%Y', '%Y-%m-%d')
DATETIME_INPUT_FORMATS = ('%d/%m/%Y %H:%M:%S', '%Y-%m-%d %H:%M:%S')
但仍然无效。
推荐答案
DATE_INPUT_FORMATS $只有在
USE_I18N = False时才会尊重
settings.py
中的c $ c>和 DATETIME_INPUT_FORMATS
/ code>
DATE_INPUT_FORMATS
and DATETIME_INPUT_FORMATS
in settings.py
are only respected when USE_I18N = False
如果您有 USE_I18N = True
,则需要使用 FORMAT_MODULE_PATH
还可以创建一些格式模块文件,如下所述:
https://docs.djangoproject.com/en/1.4/ref/settings/#format-module-path
If you have USE_I18N = True
you need to use FORMAT_MODULE_PATH
also and create some format module files, as described here:
https://docs.djangoproject.com/en/1.4/ref/settings/#format-module-path
这篇关于Django管理员显示本地化的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!