diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2021-07-13 22:15:13 -0400 |
---|---|---|
committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2021-07-16 15:51:20 +0200 |
commit | 0dc25526d8daaaa59968d4b1b597968e197f040c (patch) | |
tree | bde70ecd2cf8000c08553274903ac42bad86bd00 /django/forms/forms.py | |
parent | 788441c6ab4e0167aadc155a4362a87694e38aa5 (diff) | |
download | django-0dc25526d8daaaa59968d4b1b597968e197f040c.tar.gz |
Fixed #32924 -- Changed BaseForm.get_initial_for_field() to remove microseconds when needed.
Diffstat (limited to 'django/forms/forms.py')
-rw-r--r-- | django/forms/forms.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py index ac6ef667d9..2bf268ae76 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -3,6 +3,7 @@ Form classes """ import copy +import datetime from django.core.exceptions import NON_FIELD_ERRORS, ValidationError from django.forms.fields import Field, FileField @@ -475,6 +476,11 @@ class BaseForm: value = self.initial.get(field_name, field.initial) if callable(value): value = value() + # If this is an auto-generated default date, nix the microseconds + # for standardized handling. See #22502. + if (isinstance(value, (datetime.datetime, datetime.time)) and + not field.widget.supports_microseconds): + value = value.replace(microsecond=0) return value |