mirror of
https://github.com/django/django.git
synced 2025-10-25 14:46:09 +00:00
Fixed #32924 -- Changed BaseForm.get_initial_for_field() to remove microseconds when needed.
This commit is contained in:
committed by
Carlton Gibson
parent
788441c6ab
commit
0dc25526d8
@@ -1,4 +1,3 @@
|
||||
import datetime
|
||||
import re
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
@@ -228,13 +227,7 @@ class BoundField:
|
||||
|
||||
@cached_property
|
||||
def initial(self):
|
||||
data = self.form.get_initial_for_field(self.field, self.name)
|
||||
# If this is an auto-generated default date, nix the microseconds for
|
||||
# standardized handling. See #22502.
|
||||
if (isinstance(data, (datetime.datetime, datetime.time)) and
|
||||
not self.field.widget.supports_microseconds):
|
||||
data = data.replace(microsecond=0)
|
||||
return data
|
||||
return self.form.get_initial_for_field(self.field, self.name)
|
||||
|
||||
def build_widget_attrs(self, attrs, widget=None):
|
||||
widget = widget or self.field.widget
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user