How do I make Django's DATETIME_FORMAT active?

前端 未结 4 2034
渐次进展
渐次进展 2021-02-13 23:49

Where should DATETIME_FORMAT be placed for it to have effect on the display of date-time in the Django admin site (Django’s automatic admin interface)?

Documentation for

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-14 00:19

    This will solve the particular problem that is not possible with DATETIME_FORMAT (as it is ignored in the current Django implementations despite the documentation), is dirty too and is similar to ayaz's answer (less global - will only affect the admin site list view):

    Right after the line

    (date_format, datetime_format,time_format) = get_date_formats()

    in file (Django is usually in folder Lib/site-packages in the Python installation)

    django/contrib/admin/templatetags/admin_list.py

    overwrite the value of datetime_format (for a models.DateTimeField in the model):

    datetime_format = 'Y-m-d H:i:sO'

    And for date-only fields:

    date_format = 'Y-m-d'

    Restart of the web-server (e.g. development server) or logging out of the admin interface is NOT necessary for this change to take effect. A simple refresh in the web-browser is all what is required.

提交回复
热议问题