Opened 10 years ago

Closed 9 years ago

#4428 closed (fixed)

DateTimeField's clean() does not support millisecond resolution

Reported by: berto Owned by: Malcolm Tredinnick
Component: Forms Version: master
Severity: Keywords: datetimefield, datetimeinput
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

I ran into this problem when experimenting with newforms' form_from_instance(). When a model with a DateTimeField is saved and then retrieved using form_for_instance, the value contains milliseconds. The DateTimeField's clean() does not handle the milliseconds and validation fails. I found this snippet and incorporated it into clean():

http://www.thescripts.com/forum/thread506538.html

Attached is a patch.

Thanks!
-berto.

Attachments (4)

datetimefield_millisecond.patch (2.3 KB) - added by berto 10 years ago.
fields.diff (428 bytes) - added by Andrews Medina 9 years ago.
widgets.diff (1004 bytes) - added by Andrews Medina 9 years ago.
new_datetimefield_millisecond.diff (3.9 KB) - added by Wiliam Alves de Souza(waa) 9 years ago.
Code improvements and tests

Download all attachments as: .zip

Change History (12)

Changed 10 years ago by berto

comment:1 Changed 9 years ago by Chris Beaven

Component: Uncategorizeddjango.newforms
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:2 Changed 9 years ago by Andrews Medina

Keywords: datetimefield datetimeinput added
Owner: changed from nobody to Andrews Medina

Changed 9 years ago by Andrews Medina

Attachment: fields.diff added

Changed 9 years ago by Andrews Medina

Attachment: widgets.diff added

comment:3 Changed 9 years ago by Andrews Medina

Resolution: fixed
Status: newclosed

I create a DateTimeInput to fix this problem. The default format is settiings.DATETIME_FORMAT.
For to configure format use parameter format.

comment:4 Changed 9 years ago by Russell Keith-Magee

Resolution: fixed
Status: closedreopened

Ticket isn't fixed until it's in the tree.

comment:5 Changed 9 years ago by Philippe Raoult

Resolution: duplicate
Status: reopenedclosed

see #4487.

comment:6 Changed 9 years ago by Malcolm Tredinnick

Resolution: duplicate
Status: closedreopened

Not fixing quite the same problem as #4487, since SplitDateTime widget isn't the default for DateTime field display).

comment:7 Changed 9 years ago by Malcolm Tredinnick

Owner: changed from Andrews Medina to Malcolm Tredinnick
Status: reopenednew

Changed 9 years ago by Wiliam Alves de Souza(waa)

Code improvements and tests

comment:8 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [6578]) Changed the default form presentation of datetime values to not include the
fractional second values (they usually aren't going to be needed). Based on
patches from yi.codeplayer@…, andrews and Wiliam Alves de Souza. Fixed #4428, #4487

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