Opened 18 years ago

Closed 17 years ago

#4428 closed (fixed)

DateTimeField's clean() does not support millisecond resolution

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

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 18 years ago.
fields.diff (428 bytes ) - added by Andrews Medina 17 years ago.
widgets.diff (1004 bytes ) - added by Andrews Medina 17 years ago.
new_datetimefield_millisecond.diff (3.9 KB ) - added by Wiliam Alves de Souza(waa) 17 years ago.
Code improvements and tests

Download all attachments as: .zip

Change History (12)

by berto, 18 years ago

comment:1 by Chris Beaven, 17 years ago

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

comment:2 by Andrews Medina, 17 years ago

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

by Andrews Medina, 17 years ago

Attachment: fields.diff added

by Andrews Medina, 17 years ago

Attachment: widgets.diff added

comment:3 by Andrews Medina, 17 years ago

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 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: closedreopened

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

comment:5 by Philippe Raoult, 17 years ago

Resolution: duplicate
Status: reopenedclosed

see #4487.

comment:6 by Malcolm Tredinnick, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

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

by Wiliam Alves de Souza(waa), 17 years ago

Code improvements and tests

comment:8 by Malcolm Tredinnick, 17 years ago

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