Skip to content

Commit

Permalink
Added a possible fix
Browse files Browse the repository at this point in the history
  • Loading branch information
delinhabit committed Jul 25, 2015
1 parent 46b65d1 commit 47a22a5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions rest_framework/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
from django.utils.translation import ugettext_lazy as _

from rest_framework.compat import OrderedDict
from rest_framework.fields import Field, empty, get_attribute
from rest_framework.fields import (
Field, empty, get_attribute, is_simple_callable
)
from rest_framework.reverse import reverse
from rest_framework.utils import html

Expand Down Expand Up @@ -106,7 +108,12 @@ def get_attribute(self, instance):
# Optimized case, return a mock object only containing the pk attribute.
try:
instance = get_attribute(instance, self.source_attrs[:-1])
return PKOnlyObject(pk=instance.serializable_value(self.source_attrs[-1]))

value = instance.serializable_value(self.source_attrs[-1])
if is_simple_callable(value):
value = value().pk

return PKOnlyObject(pk=value)
except AttributeError:
pass

Expand Down

0 comments on commit 47a22a5

Please sign in to comment.