mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +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
|
||||
|
||||
def to_representation(self, value):
|
||||
if value is None:
|
||||
return None
|
||||
if self.uuid_format == 'hex_verbose':
|
||||
return str(value)
|
||||
else:
|
||||
|
|
|
@ -464,9 +464,13 @@ class Serializer(BaseSerializer):
|
|||
except SkipField:
|
||||
continue
|
||||
|
||||
if attribute is None:
|
||||
# We skip `to_representation` for `None` values so that
|
||||
# fields do not have to explicitly deal with that case.
|
||||
# We skip `to_representation` for `None` values so that 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
|
||||
else:
|
||||
ret[field.field_name] = field.to_representation(attribute)
|
||||
|
|
Loading…
Reference in New Issue
Block a user