File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 13
13
from django .utils .translation import ugettext_lazy as _
14
14
15
15
from rest_framework .compat import OrderedDict
16
- from rest_framework .fields import Field , empty , get_attribute
16
+ from rest_framework .fields import (
17
+ Field , empty , get_attribute , is_simple_callable
18
+ )
17
19
from rest_framework .reverse import reverse
18
20
from rest_framework .utils import html
19
21
@@ -106,7 +108,12 @@ def get_attribute(self, instance):
106
108
# Optimized case, return a mock object only containing the pk attribute.
107
109
try :
108
110
instance = get_attribute (instance , self .source_attrs [:- 1 ])
109
- return PKOnlyObject (pk = instance .serializable_value (self .source_attrs [- 1 ]))
111
+ value = instance .serializable_value (self .source_attrs [- 1 ])
112
+ if is_simple_callable (value ):
113
+ # Handle edge case where the relationship `source` argument
114
+ # points to a `get_relationship()` method on the model
115
+ value = value ().pk
116
+ return PKOnlyObject (pk = value )
110
117
except AttributeError :
111
118
pass
112
119
You can’t perform that action at this time.
0 commit comments