The only solutions I found is either to change `DATETIME_FORMAT`
systemwise:
{{{
from django.conf.locale.en import formats as en_formats
en_formats.DATETIME_FORMAT = "d M. Y H:i:s"
}}}
or to change the output for individual fields.
But I would like to see seconds for all DateTime fields in whole admin
interface and not to change the format in frontend nor API (which the
first solution causes).
Most importantly I feel, that all Django users would benefit from ability
to access whole information about DateTime which is stored in the
database. So my suggestion is to start outputting DateTime fields in admin
interface with tooltip containing whole precise time such as:
{{{
<div class="readonly" title="Jan. 4, 2023, 4:22:30.123 p.m.">Jan. 4, 2023,
4:22 p.m.</div>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34241>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "Snímek obrazovky_2023-01-05_10-13-50.png" added.
* Attachment "Snímek obrazovky_2023-01-05_10-13-37.png" added.
* status: new => closed
* resolution: => wontfix
Comment:
Replying to [ticket:34241 Petr Dlouhý]:
> The default output format for DateTimeField (e.g. `created`) fields in
Django admin is something like `Jan. 4, 2023, 4:22 p.m.`. When I am
debugging some issue and trying to find matching record in logs I am
lacking information about second (or even milliseconds).
Thanks for the ticket, however I find it unusual to use the admin for
debugging, especially so precise that seconds/milliseconds are needed. I'd
recommend using the `dbshell`/`shell` console to search for specific
rows/objects.
> The only solutions I found is either to change `DATETIME_FORMAT`
systemwise:
> {{{
> from django.conf.locale.en import formats as en_formats
> en_formats.DATETIME_FORMAT = "d M. Y H:i:s"
> }}}
>
> or to change the output for individual fields.
>
> But I would like to see seconds for all DateTime fields in whole admin
interface and not to change the format in frontend nor API (which the
first solution causes).
>
> Most importantly I feel, that all Django users would benefit from
ability to access whole information about DateTime which is stored in the
database. So my suggestion is to start outputting DateTime fields in admin
interface with tooltip containing whole precise time such as:
> {{{
> <div class="readonly" title="Jan. 4, 2023, 4:22:30.123 p.m.">Jan. 4,
2023, 4:22 p.m.</div>
> }}}
IMO, debugging with the admin doesn't justify pushing extra data to the UI
that are not needed and not used otherwise. You can start a discussion on
DevelopersMailingList if you don't agree.
--
Ticket URL: <https://code.djangoproject.com/ticket/34241#comment:1>
Comment (by Petr Dlouhý):
{{{
Thanks for the ticket, however I find it unusual to use the admin for
debugging, especially so precise that seconds/milliseconds are needed. I'd
recommend using the dbshell/shell console to search for specific
rows/objects.
}}}
@Mariusz Felisiak Thank you for your answer, but I am feeling that it
might be a bit out of sync with everyday production reality.
It might not be debugging per se, but if I got report by other admin about
some inconsistency in the data in admin interface I really don't want to
open `shell/dbshell` just find at what second the record was created. That
is addition substantial workload.
More importantly the seconds might be very important even for many
ordinary admin users. There might be several use-cases - for example:
- The user made two duplicate payments at same minute and want to return
one of them - then the seconds might help the admin to determine which to
refund and which to keep (or find matching record in payment system).
- Many other cases where the user needs to find matching record in some
other external database/application.
- Cases where there are several records created at same minute.
- The table has higher load and there are several records created every
minute.
- The admin user might be experienced enough in working with the data to
analyze the problem with data but not a programmer able to use
`shell/dbshell` (and it might not be desired to give him the permissions).
Overall I think that the only reason to hide the seconds from users might
be compactness of the UX, but at the same time I feel that there should be
some mechanism to either allow users to access the hidden data in whole
admin interface or at least make it possible to easily configure the
output data format in admin interface without need to change it
systemwide.
--
Ticket URL: <https://code.djangoproject.com/ticket/34241#comment:2>
* cc: Carlton Gibson (added)
Comment:
> More importantly the seconds might be very important even for many
ordinary admin users. There might be several use-cases.
Agreed, but it's not something all users need for all dates.
> ... or at least make it possible to easily configure the output data
format in admin interface without need to change it systemwide.
You can always change format for a single field, e.g
{{{#!python
class MyModelAdmin(admin.ModelAdmin):
@admin.display(description="Created with seconds")
def custom_created(self, obj):
return obj.created.strftime("d M. Y H:i:s")
list_display = (..., "custom_created")
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34241#comment:3>
Comment (by Petr Dlouhý):
{{{
Agreed, but it's not something all users need for all dates.
}}}
Most of Django features are not NEEDED for ALL users.
When I am digging deeper I see big inconsistency in the fact, that when I
am editing the field I must enter the date including seconds but then the
time is otupted in changelist_table or as readonly field without them.
{{{
You can always change format for a single field, e.g
}}}
That is not very practical nor DRY if I want to make it for every DateTime
field in admin including external applications.
Maybe there is some way to override readonly field outputs in Django admin
I am not aware of or maybe there isn't and creating something like that
would help to solve other tickets like:
https://code.djangoproject.com/ticket/30577
--
Ticket URL: <https://code.djangoproject.com/ticket/34241#comment:4>
Comment (by Mariusz Felisiak):
> Most of Django features are not NEEDED for ALL users.
But we don't force users to use them. Your proposition with `title` would
appear for all admin users.
> When I am digging deeper I see big inconsistency in the fact, that when
I am editing the field I must enter the date including seconds but then
the time is otupted in changelist_table or as readonly field without them.
I understand that you don't agree with my opinion :), so please feel-free
to start a discussion on the DevelopersMailingList, where you'll reach a
wider audience and see what other think, and
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features follow the guidelines with regards to
requesting features].
--
Ticket URL: <https://code.djangoproject.com/ticket/34241#comment:5>
Comment (by Carlton Gibson):
I'd imagine `ModelAdmin.formfield_overrides` would serve for editable
fields, with a project level base class if wanted throughout.
I don't think it's feasible for read-only fields without progress on
#30577 (which lacks even a proof-of-concept).
I agree that second and sub-second precision is not required (or desired)
in the vast majority of cases.
--
Ticket URL: <https://code.djangoproject.com/ticket/34241#comment:6>
Comment (by Petr Dlouhý):
OK. For anyone concerned I have find solution that is a bit hacky, but is
best of what I can think is possible right now:
In some `__init__.py` file:
{{{
from django.contrib.admin import utils
from django.db.models import DateTimeField
from django.utils.html import format_html
_display_for_field = utils.display_for_field
# Modify DateTime field format and display tooltip with full date and time
def display_for_field(value, field, empty_value_display):
if value and isinstance(field, DateTimeField):
return format_html(
'<span title="{}">{}</span>', value, value.strftime("%Y-%m-%d
%H:%M:%S %Z")
)
return _display_for_field(value, field, empty_value_display)
utils.display_for_field = display_for_field
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34241#comment:7>
Comment (by Claude Paroz):
I *may* see some value in adding the full iso representation of the
datetime as a data attribute of the div. It's probably still not directly
addressing the use case of this ticket, but at least would provide a way
for some clever tools to extend the UI if needed (e.g. some custom JS).
--
Ticket URL: <https://code.djangoproject.com/ticket/34241#comment:8>
Comment (by Petr Dlouhý):
@Claude Paroz That would be very nice. It might even be sufficient for the
debuging purposes, because using developer tools is much more easier than
going into shell/dbshell.
Also custom JS would be very easy option in such case (although I would
probably stick with the solution described further up).
--
Ticket URL: <https://code.djangoproject.com/ticket/34241#comment:9>