mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
[WIP/RFC] use field default value if not allow_null
This is meant to be used with FK remote field lookups (`source = 'foo.bar'`), where `foo` is a model and `bar` is `None` there. serializers.CharField(source='foo.bar', default='default')
This commit is contained in:
parent
c456b3c510
commit
929937693c
|
@ -499,6 +499,13 @@ class Serializer(BaseSerializer):
|
||||||
# resolve the pk value.
|
# resolve the pk value.
|
||||||
check_for_none = attribute.pk if isinstance(attribute, PKOnlyObject) else attribute
|
check_for_none = attribute.pk if isinstance(attribute, PKOnlyObject) else attribute
|
||||||
if check_for_none is None:
|
if check_for_none is None:
|
||||||
|
if not field.allow_null:
|
||||||
|
try:
|
||||||
|
ret[field.field_name] = field.get_default()
|
||||||
|
except SkipField:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
continue
|
||||||
ret[field.field_name] = None
|
ret[field.field_name] = None
|
||||||
else:
|
else:
|
||||||
ret[field.field_name] = field.to_representation(attribute)
|
ret[field.field_name] = field.to_representation(attribute)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user