How do I make Django's DATETIME_FORMAT active?

前端 未结 4 1254
春和景丽
春和景丽 2021-02-13 23:27

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:01

    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.

提交回复
热议问题