Add __str__ method to PKOnlyObject (#4423)

This commit is contained in:
Tom Christie 2016-08-19 14:37:27 +01:00 committed by GitHub
parent 63342e81db
commit a335309b33

View File

@ -10,7 +10,7 @@ from django.core.urlresolvers import (
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 _
@ -47,6 +47,7 @@ class Hyperlink(six.text_type):
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
@ -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.