我住在新西兰,日期格式为DD / MM / YYYY,但是admin中的日期字段显示YYYY-MM-DD,我尝试通过以下方式更改小部件:
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')
但仍然无效。
答案 0 :(得分:1)
DATE_INPUT_FORMATS
时才会尊重DATETIME_INPUT_FORMATS
中的settings.py
和USE_I18N = False
如果你有USE_I18N = True
,你还需要使用FORMAT_MODULE_PATH
并创建一些格式模块文件,如下所述:
https://docs.djangoproject.com/en/1.4/ref/settings/#format-module-path