mirror of https://github.com/django/django.git
parent
fab46ce6f5
commit
6b842c5998
|
@ -16,9 +16,6 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
__all__ = ('BoundField',)
|
__all__ = ('BoundField',)
|
||||||
|
|
||||||
|
|
||||||
UNSET = object()
|
|
||||||
|
|
||||||
|
|
||||||
@html_safe
|
@html_safe
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class BoundField(object):
|
class BoundField(object):
|
||||||
|
@ -35,7 +32,6 @@ class BoundField(object):
|
||||||
else:
|
else:
|
||||||
self.label = self.field.label
|
self.label = self.field.label
|
||||||
self.help_text = field.help_text or ''
|
self.help_text = field.help_text or ''
|
||||||
self._initial_value = UNSET
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Renders this field as an HTML widget."""
|
"""Renders this field as an HTML widget."""
|
||||||
|
@ -220,20 +216,16 @@ class BoundField(object):
|
||||||
id_ = widget.attrs.get('id') or self.auto_id
|
id_ = widget.attrs.get('id') or self.auto_id
|
||||||
return widget.id_for_label(id_)
|
return widget.id_for_label(id_)
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def initial(self):
|
def initial(self):
|
||||||
data = self.form.initial.get(self.name, self.field.initial)
|
data = self.form.initial.get(self.name, self.field.initial)
|
||||||
if callable(data):
|
if callable(data):
|
||||||
if self._initial_value is not UNSET:
|
data = data()
|
||||||
data = self._initial_value
|
# If this is an auto-generated default date, nix the microseconds
|
||||||
else:
|
# for standardized handling. See #22502.
|
||||||
data = data()
|
if (isinstance(data, (datetime.datetime, datetime.time)) and
|
||||||
# If this is an auto-generated default date, nix the
|
not self.field.widget.supports_microseconds):
|
||||||
# microseconds for standardized handling. See #22502.
|
data = data.replace(microsecond=0)
|
||||||
if (isinstance(data, (datetime.datetime, datetime.time)) and
|
|
||||||
not self.field.widget.supports_microseconds):
|
|
||||||
data = data.replace(microsecond=0)
|
|
||||||
self._initial_value = data
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def build_widget_attrs(self, attrs, widget=None):
|
def build_widget_attrs(self, attrs, widget=None):
|
||||||
|
|
Loading…
Reference in New Issue