mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-30 05:24:00 +03:00
Merge pull request #739 from craigds/basic-nested-serialization
tweaks to writable nested serializers
This commit is contained in:
commit
75fbfb5858
|
@ -129,8 +129,8 @@ class BaseSerializer(WritableField):
|
||||||
_dict_class = SortedDictWithMetadata
|
_dict_class = SortedDictWithMetadata
|
||||||
|
|
||||||
def __init__(self, instance=None, data=None, files=None,
|
def __init__(self, instance=None, data=None, files=None,
|
||||||
context=None, partial=False, many=None, source=None):
|
context=None, partial=False, many=None, **kwargs):
|
||||||
super(BaseSerializer, self).__init__(source=source)
|
super(BaseSerializer, self).__init__(**kwargs)
|
||||||
self.opts = self._options_class(self.Meta)
|
self.opts = self._options_class(self.Meta)
|
||||||
self.parent = None
|
self.parent = None
|
||||||
self.root = None
|
self.root = None
|
||||||
|
@ -358,6 +358,10 @@ class BaseSerializer(WritableField):
|
||||||
try:
|
try:
|
||||||
value = data[field_name]
|
value = data[field_name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
if self.default is not None and not self.partial:
|
||||||
|
# Note: partial updates shouldn't set defaults
|
||||||
|
value = copy.deepcopy(self.default)
|
||||||
|
else:
|
||||||
if self.required:
|
if self.required:
|
||||||
raise ValidationError(self.error_messages['required'])
|
raise ValidationError(self.error_messages['required'])
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user