diff --git a/rest_framework/utils/serializer_helpers.py b/rest_framework/utils/serializer_helpers.py index 6172ce81e..245c5f717 100644 --- a/rest_framework/utils/serializer_helpers.py +++ b/rest_framework/utils/serializer_helpers.py @@ -72,7 +72,8 @@ class BoundField(object): )) def as_form_field(self): - return self.__class__(self._field, force_text(self.value), self.errors, self._prefix) + value = force_text(self.value) + return self.__class__(self._field, value, self.errors, self._prefix) class NestedBoundField(BoundField): @@ -93,6 +94,15 @@ class NestedBoundField(BoundField): return NestedBoundField(field, value, error, prefix=self.name + '.') return BoundField(field, value, error, prefix=self.name + '.') + def as_form_field(self): + values = {} + for key, value in self.value.items(): + if isinstance(value, (list, dict)): + values[key] = value + else: + values[key] = force_text(value) + return self.__class__(self._field, values, self.errors, self._prefix) + class BindingDict(collections.MutableMapping): """