mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-26 11:33:59 +03:00
use writablefield style for serializer handling of self.default
This commit is contained in:
parent
d6d5b1d82a
commit
101fa26ebc
|
@ -358,11 +358,13 @@ class BaseSerializer(WritableField):
|
|||
try:
|
||||
value = data[field_name]
|
||||
except KeyError:
|
||||
if self.required:
|
||||
raise ValidationError(self.error_messages['required'])
|
||||
if self.default is None:
|
||||
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:
|
||||
raise ValidationError(self.error_messages['required'])
|
||||
return
|
||||
value = copy.deepcopy(self.default)
|
||||
|
||||
# Set the serializer object if it exists
|
||||
obj = getattr(self.parent.object, field_name) if self.parent.object else None
|
||||
|
|
Loading…
Reference in New Issue
Block a user