Skip to content

Commit a335309

Browse files
authored
Add __str__ method to PKOnlyObject (encode#4423)
1 parent 63342e8 commit a335309

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rest_framework/relations.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from django.db.models import Manager
1111
from django.db.models.query import QuerySet
1212
from django.utils import six
13-
from django.utils.encoding import smart_text
13+
from django.utils.encoding import python_2_unicode_compatible, smart_text
1414
from django.utils.six.moves.urllib import parse as urlparse
1515
from django.utils.translation import ugettext_lazy as _
1616

@@ -47,6 +47,7 @@ def __getnewargs__(self):
4747
is_hyperlink = True
4848

4949

50+
@python_2_unicode_compatible
5051
class PKOnlyObject(object):
5152
"""
5253
This is a mock object, used for when we only need the pk of the object
@@ -56,6 +57,9 @@ class PKOnlyObject(object):
5657
def __init__(self, pk):
5758
self.pk = pk
5859

60+
def __str__(self):
61+
return "%s" % self.pk
62+
5963

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy