Commit ea9a3d88 by Tom Christie

Merge pull request #859 from craigds/master

fix for #765
parents 80a26008 208bd991
...@@ -378,6 +378,10 @@ class BaseSerializer(WritableField): ...@@ -378,6 +378,10 @@ class BaseSerializer(WritableField):
# Set the serializer object if it exists # Set the serializer object if it exists
obj = getattr(self.parent.object, field_name) if self.parent.object else None obj = getattr(self.parent.object, field_name) if self.parent.object else None
if self.source == '*':
if value:
into.update(value)
else:
if value in (None, ''): if value in (None, ''):
into[(self.source or field_name)] = None into[(self.source or field_name)] = None
else: else:
......
...@@ -91,6 +91,17 @@ class PersonSerializer(serializers.ModelSerializer): ...@@ -91,6 +91,17 @@ class PersonSerializer(serializers.ModelSerializer):
read_only_fields = ('age',) read_only_fields = ('age',)
class NestedSerializer(serializers.Serializer):
info = serializers.Field()
class ModelSerializerWithNestedSerializer(serializers.ModelSerializer):
nested = NestedSerializer(source='*')
class Meta:
model = Person
class PersonSerializerInvalidReadOnly(serializers.ModelSerializer): class PersonSerializerInvalidReadOnly(serializers.ModelSerializer):
""" """
Testing for #652. Testing for #652.
...@@ -418,6 +429,17 @@ class ValidationTests(TestCase): ...@@ -418,6 +429,17 @@ class ValidationTests(TestCase):
except: except:
self.fail('Wrong exception type thrown.') self.fail('Wrong exception type thrown.')
def test_writable_star_source_on_nested_serializer(self):
"""
Assert that a nested serializer instantiated with source='*' correctly
expands the data into the outer serializer.
"""
serializer = ModelSerializerWithNestedSerializer(data={
'name': 'marko',
'nested': {'info': 'hi'}},
)
self.assertEqual(serializer.is_valid(), True)
class CustomValidationTests(TestCase): class CustomValidationTests(TestCase):
class CommentSerializerWithFieldValidator(CommentSerializer): class CommentSerializerWithFieldValidator(CommentSerializer):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment