From a8acdbc388aac232209fa63169389a3aaa726305 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 16 Jul 2015 12:04:38 +0100 Subject: [PATCH] Resolve issue with nested serializers in HTML forms. Closes #3153. --- rest_framework/utils/serializer_helpers.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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): """