From e7e08fd48b3f88d4eb481f5b213b923fc1db3675 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 11 Aug 2012 22:20:59 +0200 Subject: [PATCH] [py3] Replaced some __str__ methods by __unicode__ These methods actually return unicode. --- django/core/files/base.py | 2 +- django/db/models/options.py | 8 +++++--- tests/modeltests/delete/models.py | 4 +++- tests/regressiontests/comment_tests/models.py | 8 +++++--- tests/regressiontests/datatypes/models.py | 2 +- tests/regressiontests/string_lookup/models.py | 4 +++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/django/core/files/base.py b/django/core/files/base.py index 87fa8bc8ec..4ad0be4fd8 100644 --- a/django/core/files/base.py +++ b/django/core/files/base.py @@ -130,7 +130,7 @@ class ContentFile(File): super(ContentFile, self).__init__(BytesIO(content), name=name) self.size = len(content) - def __str__(self): + def __unicode__(self): return 'Raw content' def __bool__(self): diff --git a/django/db/models/options.py b/django/db/models/options.py index 2e8ccb49ce..9211a76b68 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + import re from bisect import bisect @@ -8,7 +10,7 @@ from django.db.models.fields import AutoField, FieldDoesNotExist from django.db.models.fields.proxy import OrderWrt from django.db.models.loading import get_models, app_cache_ready from django.utils.translation import activate, deactivate_all, get_language, string_concat -from django.utils.encoding import force_text, smart_bytes +from django.utils.encoding import force_text, smart_text from django.utils.datastructures import SortedDict from django.utils import six @@ -198,8 +200,8 @@ class Options(object): def __repr__(self): return '' % self.object_name - def __str__(self): - return "%s.%s" % (smart_bytes(self.app_label), smart_bytes(self.module_name)) + def __unicode__(self): + return "%s.%s" % (smart_text(self.app_label), smart_text(self.module_name)) def verbose_name_raw(self): """ diff --git a/tests/modeltests/delete/models.py b/tests/modeltests/delete/models.py index f8b78eb7b7..7e7766e824 100644 --- a/tests/modeltests/delete/models.py +++ b/tests/modeltests/delete/models.py @@ -1,10 +1,12 @@ +from __future__ import unicode_literals + from django.db import models class R(models.Model): is_default = models.BooleanField(default=False) - def __str__(self): + def __unicode__(self): return "%s" % self.pk diff --git a/tests/regressiontests/comment_tests/models.py b/tests/regressiontests/comment_tests/models.py index 4093af14b5..7e16e48419 100644 --- a/tests/regressiontests/comment_tests/models.py +++ b/tests/regressiontests/comment_tests/models.py @@ -3,6 +3,8 @@ Comments may be attached to any object. See the comment documentation for more information. """ +from __future__ import unicode_literals + from django.db import models @@ -10,14 +12,14 @@ class Author(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) - def __str__(self): + def __unicode__(self): return '%s %s' % (self.first_name, self.last_name) class Article(models.Model): author = models.ForeignKey(Author) headline = models.CharField(max_length=100) - def __str__(self): + def __unicode__(self): return self.headline class Entry(models.Model): @@ -26,7 +28,7 @@ class Entry(models.Model): pub_date = models.DateField() enable_comments = models.BooleanField() - def __str__(self): + def __unicode__(self): return self.title class Book(models.Model): diff --git a/tests/regressiontests/datatypes/models.py b/tests/regressiontests/datatypes/models.py index 332ce84307..d220d0893a 100644 --- a/tests/regressiontests/datatypes/models.py +++ b/tests/regressiontests/datatypes/models.py @@ -18,7 +18,7 @@ class Donut(models.Model): class Meta: ordering = ('consumed_at',) - def __str__(self): + def __unicode__(self): return self.name class RumBaba(models.Model): diff --git a/tests/regressiontests/string_lookup/models.py b/tests/regressiontests/string_lookup/models.py index 53687a22cb..0704890cd7 100644 --- a/tests/regressiontests/string_lookup/models.py +++ b/tests/regressiontests/string_lookup/models.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals + from django.db import models @@ -42,5 +44,5 @@ class Article(models.Model): text = models.TextField() submitted_from = models.IPAddressField(blank=True, null=True) - def __str__(self): + def __unicode__(self): return "Article %s" % self.name