Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add __str__ method to PKOnlyObject
  • Loading branch information
lovelydinosaur committed Aug 19, 2016
commit 63a0dcab2efde119bf6cbeeb4bfeaa236c93c336
6 changes: 5 additions & 1 deletion rest_framework/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.db.models import Manager
from django.db.models.query import QuerySet
from django.utils import six
from django.utils.encoding import smart_text
from django.utils.encoding import python_2_unicode_compatible, smart_text
from django.utils.six.moves.urllib import parse as urlparse
from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -47,6 +47,7 @@ def __getnewargs__(self):
is_hyperlink = True


@python_2_unicode_compatible
class PKOnlyObject(object):
"""
This is a mock object, used for when we only need the pk of the object
Expand All @@ -56,6 +57,9 @@ class PKOnlyObject(object):
def __init__(self, pk):
self.pk = pk

def __str__(self):
return "%s" % self.pk


# We assume that 'validators' are intended for the child serializer,
# rather than the parent serializer.
Expand Down