mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 12:30:11 +03:00
Field 'allow_null' provides serialization default
This commit is contained in:
parent
ddeecdec51
commit
c6bc7ffb28
|
@ -311,10 +311,6 @@ class Field(object):
|
||||||
self._creation_counter = Field._creation_counter
|
self._creation_counter = Field._creation_counter
|
||||||
Field._creation_counter += 1
|
Field._creation_counter += 1
|
||||||
|
|
||||||
# If `default` is unset, then use `None` when allow_null is `True`.
|
|
||||||
if default is empty and allow_null:
|
|
||||||
default = None
|
|
||||||
|
|
||||||
# If `required` is unset, then use `True` unless a default is provided.
|
# If `required` is unset, then use `True` unless a default is provided.
|
||||||
if required is None:
|
if required is None:
|
||||||
required = default is empty and not read_only
|
required = default is empty and not read_only
|
||||||
|
@ -446,6 +442,8 @@ class Field(object):
|
||||||
except (KeyError, AttributeError) as exc:
|
except (KeyError, AttributeError) as exc:
|
||||||
if self.default is not empty:
|
if self.default is not empty:
|
||||||
return self.get_default()
|
return self.get_default()
|
||||||
|
if self.allow_null:
|
||||||
|
return None
|
||||||
if not self.required:
|
if not self.required:
|
||||||
raise SkipField()
|
raise SkipField()
|
||||||
msg = (
|
msg = (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user