Opened 3 hours ago
Closed 110 minutes ago
#35951 closed Cleanup/optimization (wontfix)
Django handling of datetimes in the admin interface can be greatly improved
Reported by: | Kevin Renskers | Owned by: | |
---|---|---|---|
Component: | contrib.admin | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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.
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 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
Change History (1)
comment:1 by , 110 minutes ago
Component: | Uncategorized → contrib.admin |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
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 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 the documented guidelines for requesting features.