Skip to content

Commit 0c09642

Browse files
committed
fix unicode error in TaggedItem.__str__ on py2
this was caused by trying to format unicode data into a byte string
1 parent 49f6626 commit 0c09642

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

tagging/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.contrib.contenttypes import generic
55
from django.contrib.contenttypes.models import ContentType
66
from django.db import connection, models
7-
from django.utils.encoding import python_2_unicode_compatible
7+
from django.utils.encoding import python_2_unicode_compatible, smart_text
88
from django.utils.translation import ugettext_lazy as _
99

1010
from . import settings
@@ -487,4 +487,4 @@ class Meta:
487487
verbose_name_plural = _('tagged items')
488488

489489
def __str__(self):
490-
return '%s [%s]' % (self.object, self.tag)
490+
return '%s [%s]' % (smart_text(self.object), smart_text(self.tag))

tagging/tests/tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django import forms
77
from django.db.models import Q
88
from django.test import TestCase
9+
from django.utils import six
910

1011
from tagging import settings
1112
from tagging.forms import TagField
@@ -333,7 +334,7 @@ def test_unicode_tagged_object(self):
333334
Tag.objects.update_tags(self.dead_parrot, u'föo')
334335
items = TaggedItem.objects.all()
335336
self.assertEqual(len(items), 1)
336-
self.assertEqual(unicode(items[0]), u"dëad [föo]")
337+
self.assertEqual(six.text_type(items[0]), u"dëad [föo]")
337338

338339
def test_update_tags_with_none(self):
339340
# start off in a known, mildly interesting state

0 commit comments

Comments
 (0)