1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

Fixed #25294 -- Allowed custom BoundFields on forms.

This commit is contained in:
Moritz Sichert
2015-08-10 10:55:49 +02:00
committed by Tim Graham
parent 8615e41586
commit 535809e121
6 changed files with 68 additions and 1 deletions

View File

@@ -204,6 +204,14 @@ class Field(six.with_metaclass(RenameFieldMethods, object)):
data_value = data if data is not None else ''
return initial_value != data_value
def get_bound_field(self, form, field_name):
"""
Return a BoundField instance that will be used when accessing the form
field in a template.
"""
from django.forms.forms import BoundField
return BoundField(form, self, field_name)
def __deepcopy__(self, memo):
result = copy.copy(self)
memo[id(self)] = result

View File

@@ -152,7 +152,7 @@ class BaseForm(object):
raise KeyError(
"Key %r not found in '%s'" % (name, self.__class__.__name__))
if name not in self._bound_fields_cache:
self._bound_fields_cache[name] = BoundField(self, field, name)
self._bound_fields_cache[name] = field.get_bound_field(self, name)
return self._bound_fields_cache[name]
@property