Loading django/db/models/base.py +2 −0 Original line number Diff line number Diff line Loading @@ -404,6 +404,8 @@ class Model(six.with_metaclass(ModelBase, object)): u = six.text_type(self) except (UnicodeEncodeError, UnicodeDecodeError): u = '[Bad Unicode data]' if not six.PY3: u = u.encode('ascii', 'replace') return smart_str('<%s: %s>' % (self.__class__.__name__, u)) def __str__(self): Loading tests/regressiontests/model_regress/tests.py +10 −0 Original line number Diff line number Diff line # coding: utf-8 from __future__ import absolute_import, unicode_literals import datetime Loading Loading @@ -146,6 +148,14 @@ class ModelTests(TestCase): b = BrokenUnicodeMethod.objects.create(name="Jerry") self.assertEqual(repr(b), "<BrokenUnicodeMethod: [Bad Unicode data]>") def test_no_unicode_in_repr(self): a = Article.objects.create( headline="Watch for umlauts: üöä", pub_date=datetime.datetime.now()) if six.PY3: self.assertEqual(repr(a), '<Article: Watch for umlauts: üöä>') else: self.assertEqual(repr(a), '<Article: Watch for umlauts: ???>') @skipUnlessDBFeature("supports_timezones") def test_timezones(self): # Saving an updating with timezone-aware datetime Python objects. Loading Loading
django/db/models/base.py +2 −0 Original line number Diff line number Diff line Loading @@ -404,6 +404,8 @@ class Model(six.with_metaclass(ModelBase, object)): u = six.text_type(self) except (UnicodeEncodeError, UnicodeDecodeError): u = '[Bad Unicode data]' if not six.PY3: u = u.encode('ascii', 'replace') return smart_str('<%s: %s>' % (self.__class__.__name__, u)) def __str__(self): Loading
tests/regressiontests/model_regress/tests.py +10 −0 Original line number Diff line number Diff line # coding: utf-8 from __future__ import absolute_import, unicode_literals import datetime Loading Loading @@ -146,6 +148,14 @@ class ModelTests(TestCase): b = BrokenUnicodeMethod.objects.create(name="Jerry") self.assertEqual(repr(b), "<BrokenUnicodeMethod: [Bad Unicode data]>") def test_no_unicode_in_repr(self): a = Article.objects.create( headline="Watch for umlauts: üöä", pub_date=datetime.datetime.now()) if six.PY3: self.assertEqual(repr(a), '<Article: Watch for umlauts: üöä>') else: self.assertEqual(repr(a), '<Article: Watch for umlauts: ???>') @skipUnlessDBFeature("supports_timezones") def test_timezones(self): # Saving an updating with timezone-aware datetime Python objects. Loading