mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-05-12 20:03:44 +03:00
Bring check for null fk to BaseSerializer.to_representation
This commit is contained in:
parent
cbb8d8d254
commit
2ef74cfa61
|
@ -778,8 +778,6 @@ class UUIDField(Field):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
if value is None:
|
|
||||||
return None
|
|
||||||
if self.uuid_format == 'hex_verbose':
|
if self.uuid_format == 'hex_verbose':
|
||||||
return str(value)
|
return str(value)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -464,9 +464,13 @@ class Serializer(BaseSerializer):
|
||||||
except SkipField:
|
except SkipField:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if attribute is None:
|
# We skip `to_representation` for `None` values so that fields do
|
||||||
# We skip `to_representation` for `None` values so that
|
# not have to explicitly deal with that case.
|
||||||
# fields do not have to explicitly deal with that case.
|
#
|
||||||
|
# For related fields with `use_pk_only_optimization` we need to
|
||||||
|
# resolve the pk value.
|
||||||
|
check_for_none = attribute.pk if isinstance(attribute, PKOnlyObject) else attribute
|
||||||
|
if check_for_none is None:
|
||||||
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