mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 08:59:54 +03:00
Fix related field pk-only optimization for props
This commit is contained in:
parent
3c445d14d3
commit
bb09a18312
|
@ -175,8 +175,13 @@ class RelatedField(Field):
|
||||||
value = attribute_instance.serializable_value(self.source_attrs[-1])
|
value = attribute_instance.serializable_value(self.source_attrs[-1])
|
||||||
if is_simple_callable(value):
|
if is_simple_callable(value):
|
||||||
# Handle edge case where the relationship `source` argument
|
# Handle edge case where the relationship `source` argument
|
||||||
# points to a `get_relationship()` method on the model
|
# points to a `get_relationship()` method on the model.
|
||||||
value = value().pk
|
value = value()
|
||||||
|
|
||||||
|
# Handle edge case where relationship `source` argument points
|
||||||
|
# to an instance instead of a pk (e.g., a `@property`).
|
||||||
|
value = getattr(value, 'pk', value)
|
||||||
|
|
||||||
return PKOnlyObject(pk=value)
|
return PKOnlyObject(pk=value)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in New Issue
Block a user