Opened 7 years ago

Last modified 7 years ago

#28090 closed Bug

TimeField rendering in admin forms — at Initial Version

Reported by: Tomek Rej Owned by: nobody
Component: Forms Version: 1.11
Severity: Normal Keywords:
Cc: ygan@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When passing a datetime.Time instance to the choices parameter in a TimeField, the admin template converts it to a human readable form. Eg Time(0, 0) gets converted to "midnight", Time(1, 30) gets converted to 1:30 a.m. In Django 1.10 it gets formatted as 00:00:00 and 01:30:00 respectively.

An example of the choices I pass in to the constructor is:

[
    (datetime.Time(0, 0), '00:00'),
    (datetime.Time(0, 30), '00:30'),
    (datetime.Time(1, 0), '01:00'),
    ....,
    (datetime.Time(23, 30), '23:30')
]

This causes the admin form validation to fail with errors like the following:
Select a valid choice. midnight is not one of the available choices.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top