aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/api-guide/pagination.md2
-rw-r--r--rest_framework/utils/representation.py3
-rw-r--r--tests/test_serializer.py17
3 files changed, 20 insertions, 2 deletions
diff --git a/docs/api-guide/pagination.md b/docs/api-guide/pagination.md
index 9b7086c5..83429292 100644
--- a/docs/api-guide/pagination.md
+++ b/docs/api-guide/pagination.md
@@ -128,7 +128,7 @@ For example, to nest a pair of links labelled 'prev' and 'next', and set the nam
class CustomPaginationSerializer(pagination.BasePaginationSerializer):
links = LinksSerializer(source='*') # Takes the page object as the source
- total_results = serializers.Field(source='paginator.count')
+ total_results = serializers.ReadOnlyField(source='paginator.count')
results_field = 'objects'
diff --git a/rest_framework/utils/representation.py b/rest_framework/utils/representation.py
index 3f17a8b9..0fdb4775 100644
--- a/rest_framework/utils/representation.py
+++ b/rest_framework/utils/representation.py
@@ -2,6 +2,7 @@
Helper functions for creating user-friendly representations
of serializer classes and serializer fields.
"""
+from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import force_text
from django.utils.functional import Promise
@@ -24,7 +25,7 @@ def smart_repr(value):
if isinstance(value, Promise) and value._delegate_text:
value = force_text(value)
- value = repr(value)
+ value = repr(value).decode('utf-8')
# Representations like u'help text'
# should simply be presented as 'help text'
diff --git a/tests/test_serializer.py b/tests/test_serializer.py
index 56b39095..48fcc83b 100644
--- a/tests/test_serializer.py
+++ b/tests/test_serializer.py
@@ -1,3 +1,4 @@
+# coding: utf-8
from __future__ import unicode_literals
from rest_framework import serializers
import pytest
@@ -197,3 +198,19 @@ class TestIncorrectlyConfigured:
"The serializer field might be named incorrectly and not match any attribute or key on the `ExampleObject` instance.\n"
"Original exception text was:"
)
+
+
+class TestUnicodeRepr:
+ def test_unicode_repr(self):
+ class ExampleSerializer(serializers.Serializer):
+ example = serializers.CharField()
+
+ class ExampleObject:
+ def __init__(self):
+ self.example = '한국'
+ def __repr__(self):
+ return self.example.encode('utf8')
+
+ instance = ExampleObject()
+ serializer = ExampleSerializer(instance)
+ repr(serializer)