Opened 8 years ago

Closed 7 years ago

#4428 closed (fixed)

DateTimeField's clean() does not support millisecond resolution

Reported by: berto Owned by: mtredinnick
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 8 years ago.
fields.diff (428 bytes) - added by andrews 8 years ago.
widgets.diff (1004 bytes) - added by andrews 8 years ago.
new_datetimefield_millisecond.diff (3.9 KB) - added by Wiliam Alves de Souza(waa) 8 years ago.
Code improvements and tests

Download all attachments as: .zip

Change History (12)

Changed 8 years ago by berto

comment:1 Changed 8 years ago by SmileyChris

  • Component changed from Uncategorized to django.newforms
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 8 years ago by andrews

  • Keywords datetimefield datetimeinput added
  • Owner changed from nobody to andrews

Changed 8 years ago by andrews

Changed 8 years ago by andrews

comment:3 Changed 8 years ago by andrews

  • Resolution set to fixed
  • Status changed from new to closed

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 8 years ago by russellm

  • Resolution fixed deleted
  • Status changed from closed to reopened

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

comment:5 Changed 8 years ago by PhiR

  • Resolution set to duplicate
  • Status changed from reopened to closed

see #4487.

comment:6 Changed 8 years ago by mtredinnick

  • Resolution duplicate deleted
  • Status changed from closed to reopened

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

comment:7 Changed 8 years ago by mtredinnick

  • Owner changed from andrews to mtredinnick
  • Status changed from reopened to new

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

Code improvements and tests

comment:8 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(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