[Django] #35951: Django handling of datetimes in the admin interface can be greatly improved

12 views
Skip to first unread message

Django

unread,
Nov 28, 2024, 9:43:28 AM11/28/24
to django-...@googlegroups.com
#35951: Django handling of datetimes in the admin interface can be greatly improved
--------------------------------+-----------------------------------------
Reporter: Kevin Renskers | Type: Uncategorized
Status: new | Component: Uncategorized
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+-----------------------------------------
Some background info first. Here are my Django settings:

{{{
USE_I18N = True
USE_L10N = True
USE_TZ = True
TIME_ZONE = "UTC"
}}}

And you should know that I am in the Amsterdam timezone, `UTC+1`.

I don't really understand the way Django handles its `DateTimeField` in
the admin forms. Like, the warning "Note: You are 1 hour ahead of server
time." is so incredibly unhelpful. It doesn't make it clear if I should
enter dates in my local time or in UTC. Why doesn't it just say "Date and
time are in UTC"? That would make it super clear how I should enter the
values, which the note does not.

[[Image(https://media.hachyderm.io/media_attachments/files/113/560/954/884/415/973/original/2b3c138c50bb1b04.png)]]
[[Image(https://media.hachyderm.io/media_attachments/files/113/560/954/883/756/133/original/f56092ca574ff8b5.png)]]

At the moment I am adding `help_text="Date and time are in UTC"` to all my
`DateTimeField` instances, and hiding Django's note with the following
css:

{{{
.timezonewarning {
display: none;
}
}}}

Because our admins just don't know what to enter in these fields with the
default note.

And then when these values are shown in the admin interface, it shows them
in UTC as well, rather than translated to the browser's timezone. Which is
fine for me, but why? Why even show that warning then? For example, I
enter `2024-11-28 15:00:00` into one of the my DateTimeFields. This is
entered as a UTC datetime, right? In the database it's stored as
`2024-11-28 16:00:00+01`, which is indeed 15:00 in UTC. (Weird that it
doesn't store it that way, but ok.)

And then when displaying this value in the admin, it shows `Nov. 28, 2024,
3 p.m.`. Why does it not show `4 p.m.`, aka my local timezone? Why show
that weird note about being ahead of server time? And why is the time not
stored with `+00` in the db?

Django doesn't know my user's timezone, since this is not something that's
stored in the `User` model. But, it can use the browser's timezone to show
these dates and times in the local timezone, right? Or another option: add
a timezone picker to the top menu, next to the theme switcher for example.

The [https://docs.djangoproject.com/en/5.1/topics/i18n/timezones/ docs]
say this:

> When support for time zones is enabled, Django stores datetime
information in UTC in the database, uses time-zone-aware datetime objects
internally, and translates them to the end user’s time zone in templates
and forms.

So I guess I just don't really understand the logic behind the timezone
handling, and why it shows UTC everywhere in the admin.

Link to Discord thread where it was suggested to create a ticket:
https://discord.com/channels/856567261900832808/1311696417256898570
--
Ticket URL: <https://code.djangoproject.com/ticket/35951>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 28, 2024, 10:59:10 AM11/28/24
to django-...@googlegroups.com
#35951: Django handling of datetimes in the admin interface can be greatly improved
-------------------------------------+-------------------------------------
Reporter: Kevin Renskers | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* component: Uncategorized => contrib.admin
* resolution: => wontfix
* status: new => closed
* type: Uncategorized => Cleanup/optimization

Comment:

The warning was added in #20663 and this is mostly to do with when you use
the "Now" widget, so when they click "Now" there is an offset and the
warning is about that offset

This discussion should be moved to the
[https://forum.djangoproject.com/c/internals/5 Django Forum], this isn't
in a clear state in terms of what the problem is and what should be
addressed.
If the community comes to a consensus that a change is required and what
kind of change is required - we can re-open it.
For more information, please refer to
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features].
--
Ticket URL: <https://code.djangoproject.com/ticket/35951#comment:1>

Django

unread,
Nov 28, 2024, 3:36:58 PM11/28/24
to django-...@googlegroups.com
#35951: Django handling of datetimes in the admin interface can be greatly improved
-------------------------------------+-------------------------------------
Reporter: Kevin Renskers | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Kevin Renskers):

I thought the problem was pretty clear? But no worries, here is the forum
discussion: https://forum.djangoproject.com/t/djangos-handling-of-
datetimes-in-the-admin-interface-can-be-greatly-improved/36823.
--
Ticket URL: <https://code.djangoproject.com/ticket/35951#comment:2>

Django

unread,
Nov 29, 2024, 7:15:08 AM11/29/24
to django-...@googlegroups.com
#35951: Django handling of datetimes in the admin interface can be greatly improved
-------------------------------------+-------------------------------------
Reporter: Kevin Renskers | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* reporter: Kevin Renskers => Kevin Renskers

--
Ticket URL: <https://code.djangoproject.com/ticket/35951#comment:3>
Django <https://code.djangoproject.com/>
The web framework for perfectionists with deadlines.

Django

unread,
Sep 11, 2025, 7:10:02 AM (4 days ago) Sep 11
to django-...@googlegroups.com
#35951: Django handling of datetimes in the admin interface can be greatly improved
-------------------------------------+-------------------------------------
Reporter: Kevin Renskers | Owner: (none)
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 5.1
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Kevin Renskers):

Can we reopen this ticket? There is clear consensus on the forum
(https://forum.djangoproject.com/t/djangos-handling-of-datetimes-in-the-
admin-interface-can-be-greatly-improved/36823) that at least the note
should be changed.

> I think it is clear that the community has come to a consensus that this
message is confusing and needs to be fixed. (I’m talking about the message
“Note: You are 1 hour ahead of server time.”). It seems pretty clear that
everyone is agreed that the message should be changed to mention the
expected time zone.

By explicitly showing the timezone instead of the offset, the usability
would improve a lot.

Separately from that I do think that a timezone picker in the top menu
would be a great improvements, which is why I created
https://github.com/django/new-features/issues/76. But let's start by
changing the note?
--
Ticket URL: <https://code.djangoproject.com/ticket/35951#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages