mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +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])
|
||||
if is_simple_callable(value):
|
||||
# Handle edge case where the relationship `source` argument
|
||||
# points to a `get_relationship()` method on the model
|
||||
value = value().pk
|
||||
# points to a `get_relationship()` method on the model.
|
||||
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)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue
Block a user