summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-08-12 12:32:08 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-08-12 14:44:40 +0200
commitd4a0b27838c815af87698920cc4db7d2afd6f05b (patch)
tree6fedc7203389ab1f80f8cc7e913230c51e9b8776
parent79d62a71751140315227891bbe175630f9d3edc3 (diff)
[py3] Refactored __unicode__ to __str__.
* Renamed the __unicode__ methods * Applied the python_2_unicode_compatible decorator * Removed the StrAndUnicode mix-in that is superseded by python_2_unicode_compatible * Kept the __unicode__ methods in classes that specifically test it under Python 2
-rw-r--r--django/contrib/admin/models.py4
-rw-r--r--django/contrib/auth/models.py13
-rw-r--r--django/contrib/comments/models.py7
-rw-r--r--django/contrib/contenttypes/models.py4
-rw-r--r--django/contrib/contenttypes/tests.py4
-rw-r--r--django/contrib/databrowse/datastructures.py4
-rw-r--r--django/contrib/databrowse/tests.py10
-rw-r--r--django/contrib/flatpages/models.py4
-rw-r--r--django/contrib/gis/db/backends/base.py4
-rw-r--r--django/contrib/gis/db/backends/oracle/models.py4
-rw-r--r--django/contrib/gis/db/backends/postgis/models.py4
-rw-r--r--django/contrib/gis/db/backends/spatialite/models.py4
-rw-r--r--django/contrib/gis/maps/google/overlays.py7
-rw-r--r--django/contrib/gis/tests/distapp/models.py22
-rw-r--r--django/contrib/gis/tests/geo3d/models.py26
-rw-r--r--django/contrib/gis/tests/geoadmin/models.py4
-rw-r--r--django/contrib/gis/tests/geoapp/models.py16
-rw-r--r--django/contrib/gis/tests/geogapp/models.py10
-rw-r--r--django/contrib/gis/tests/relatedapp/models.py14
-rw-r--r--django/contrib/gis/utils/ogrinspect.py2
-rw-r--r--django/contrib/messages/storage/base.py7
-rw-r--r--django/contrib/redirects/models.py6
-rw-r--r--django/contrib/sites/models.py7
-rw-r--r--django/core/files/base.py7
-rw-r--r--django/core/files/uploadhandler.py4
-rw-r--r--django/db/models/options.py4
-rw-r--r--django/forms/forms.py12
-rw-r--r--django/forms/formsets.py7
-rw-r--r--django/forms/util.py12
-rw-r--r--django/forms/widgets.py20
-rw-r--r--django/template/base.py4
-rw-r--r--django/test/html.py7
-rw-r--r--tests/modeltests/aggregation/models.py13
-rw-r--r--tests/modeltests/basic/models.py4
-rw-r--r--tests/modeltests/choices/models.py4
-rw-r--r--tests/modeltests/custom_columns/models.py7
-rw-r--r--tests/modeltests/custom_managers/models.py10
-rw-r--r--tests/modeltests/custom_methods/models.py4
-rw-r--r--tests/modeltests/custom_pk/fields.py4
-rw-r--r--tests/modeltests/custom_pk/models.py10
-rw-r--r--tests/modeltests/defer/models.py4
-rw-r--r--tests/modeltests/delete/models.py4
-rw-r--r--tests/modeltests/distinct_on_fields/models.py13
-rw-r--r--tests/modeltests/expressions/models.py7
-rw-r--r--tests/modeltests/field_defaults/models.py4
-rw-r--r--tests/modeltests/field_subclassing/fields.py4
-rw-r--r--tests/modeltests/field_subclassing/models.py4
-rw-r--r--tests/modeltests/fixtures/models.py22
-rw-r--r--tests/modeltests/fixtures_model_package/models/__init__.py4
-rw-r--r--tests/modeltests/generic_relations/models.py16
-rw-r--r--tests/modeltests/get_latest/models.py7
-rw-r--r--tests/modeltests/get_object_or_404/models.py7
-rw-r--r--tests/modeltests/get_or_create/models.py4
-rw-r--r--tests/modeltests/lookup/models.py13
-rw-r--r--tests/modeltests/m2m_and_m2o/models.py4
-rw-r--r--tests/modeltests/m2m_intermediary/models.py10
-rw-r--r--tests/modeltests/m2m_multiple/models.py7
-rw-r--r--tests/modeltests/m2m_recursive/models.py4
-rw-r--r--tests/modeltests/m2m_signals/models.py10
-rw-r--r--tests/modeltests/m2m_through/models.py16
-rw-r--r--tests/modeltests/m2o_recursive/models.py7
-rw-r--r--tests/modeltests/many_to_many/models.py7
-rw-r--r--tests/modeltests/many_to_one/models.py7
-rw-r--r--tests/modeltests/many_to_one_null/models.py7
-rw-r--r--tests/modeltests/model_forms/models.py46
-rw-r--r--tests/modeltests/model_formsets/models.py55
-rw-r--r--tests/modeltests/model_inheritance/models.py28
-rw-r--r--tests/modeltests/model_inheritance_same_model_name/models.py4
-rw-r--r--tests/modeltests/one_to_one/models.py13
-rw-r--r--tests/modeltests/or_lookups/models.py4
-rw-r--r--tests/modeltests/order_with_respect_to/models.py7
-rw-r--r--tests/modeltests/ordering/models.py7
-rw-r--r--tests/modeltests/pagination/models.py4
-rw-r--r--tests/modeltests/prefetch_related/models.py22
-rw-r--r--tests/modeltests/proxy_models/models.py13
-rw-r--r--tests/modeltests/reserved_names/models.py6
-rw-r--r--tests/modeltests/reverse_lookup/models.py10
-rw-r--r--tests/modeltests/save_delete_hooks/models.py4
-rw-r--r--tests/modeltests/select_related/models.py27
-rw-r--r--tests/modeltests/serializers/models.py25
-rw-r--r--tests/modeltests/signals/models.py7
-rw-r--r--tests/modeltests/str/models.py6
-rw-r--r--tests/modeltests/transactions/models.py4
-rw-r--r--tests/modeltests/unmanaged_models/models.py19
-rw-r--r--tests/modeltests/update/models.py7
-rw-r--r--tests/modeltests/update_only_fields/models.py7
-rw-r--r--tests/modeltests/validation/models.py4
-rw-r--r--tests/regressiontests/admin_changelist/models.py7
-rw-r--r--tests/regressiontests/admin_custom_urls/models.py4
-rw-r--r--tests/regressiontests/admin_filters/models.py10
-rw-r--r--tests/regressiontests/admin_inlines/models.py10
-rw-r--r--tests/regressiontests/admin_scripts/models.py4
-rw-r--r--tests/regressiontests/admin_util/models.py4
-rw-r--r--tests/regressiontests/admin_validation/models.py4
-rw-r--r--tests/regressiontests/admin_views/models.py91
-rw-r--r--tests/regressiontests/admin_widgets/models.py24
-rw-r--r--tests/regressiontests/aggregation_regress/models.py16
-rw-r--r--tests/regressiontests/backends/models.py13
-rw-r--r--tests/regressiontests/comment_tests/models.py10
-rw-r--r--tests/regressiontests/custom_columns_regress/models.py7
-rw-r--r--tests/regressiontests/custom_managers_regress/models.py10
-rw-r--r--tests/regressiontests/datatypes/models.py4
-rw-r--r--tests/regressiontests/dates/models.py7
-rw-r--r--tests/regressiontests/defaultfilters/tests.py4
-rw-r--r--tests/regressiontests/defer_regress/models.py10
-rw-r--r--tests/regressiontests/expressions_regress/models.py4
-rw-r--r--tests/regressiontests/extra_regress/models.py7
-rw-r--r--tests/regressiontests/fixtures_regress/models.py25
-rw-r--r--tests/regressiontests/forms/models.py7
-rw-r--r--tests/regressiontests/forms/tests/error_messages.py4
-rw-r--r--tests/regressiontests/forms/tests/extra.py28
-rw-r--r--tests/regressiontests/forms/tests/util.py4
-rw-r--r--tests/regressiontests/forms/tests/widgets.py7
-rw-r--r--tests/regressiontests/generic_inline_admin/models.py4
-rw-r--r--tests/regressiontests/generic_relations_regress/models.py16
-rw-r--r--tests/regressiontests/generic_views/models.py10
-rw-r--r--tests/regressiontests/inline_formsets/models.py7
-rw-r--r--tests/regressiontests/introspection/models.py7
-rw-r--r--tests/regressiontests/m2m_regress/models.py13
-rw-r--r--tests/regressiontests/m2m_through_regress/models.py13
-rw-r--r--tests/regressiontests/managers_regress/models.py19
-rw-r--r--tests/regressiontests/many_to_one_regress/models.py7
-rw-r--r--tests/regressiontests/model_forms_regress/models.py7
-rw-r--r--tests/regressiontests/model_formsets_regress/models.py4
-rw-r--r--tests/regressiontests/model_inheritance_regress/models.py28
-rw-r--r--tests/regressiontests/model_inheritance_select_related/models.py10
-rw-r--r--tests/regressiontests/model_regress/models.py13
-rw-r--r--tests/regressiontests/modeladmin/models.py4
-rw-r--r--tests/regressiontests/multiple_database/models.py13
-rw-r--r--tests/regressiontests/null_fk/models.py7
-rw-r--r--tests/regressiontests/null_fk_ordering/models.py10
-rw-r--r--tests/regressiontests/null_queries/models.py7
-rw-r--r--tests/regressiontests/one_to_one_regress/models.py13
-rw-r--r--tests/regressiontests/queries/models.py79
-rw-r--r--tests/regressiontests/select_related_onetoone/models.py16
-rw-r--r--tests/regressiontests/select_related_regress/models.py19
-rw-r--r--tests/regressiontests/signals_regress/models.py7
-rw-r--r--tests/regressiontests/sites_framework/models.py4
-rw-r--r--tests/regressiontests/string_lookup/models.py19
-rw-r--r--tests/regressiontests/syndication/models.py7
-rw-r--r--tests/regressiontests/templates/filters.py17
-rw-r--r--tests/regressiontests/views/models.py7
142 files changed, 1072 insertions, 481 deletions
diff --git a/django/contrib/admin/models.py b/django/contrib/admin/models.py
index e31c6d84ed..2b12edd4e2 100644
--- a/django/contrib/admin/models.py
+++ b/django/contrib/admin/models.py
@@ -6,6 +6,7 @@ from django.contrib.auth.models import User
from django.contrib.admin.util import quote
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_text
+from django.utils.encoding import python_2_unicode_compatible
ADDITION = 1
CHANGE = 2
@@ -16,6 +17,7 @@ class LogEntryManager(models.Manager):
e = self.model(None, None, user_id, content_type_id, smart_text(object_id), object_repr[:200], action_flag, change_message)
e.save()
+@python_2_unicode_compatible
class LogEntry(models.Model):
action_time = models.DateTimeField(_('action time'), auto_now=True)
user = models.ForeignKey(User)
@@ -36,7 +38,7 @@ class LogEntry(models.Model):
def __repr__(self):
return smart_text(self.action_time)
- def __unicode__(self):
+ def __str__(self):
if self.action_flag == ADDITION:
return _('Added "%(object)s".') % {'object': self.object_repr}
elif self.action_flag == CHANGE:
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index a39165c92c..1c21917a8c 100644
--- a/django/contrib/auth/models.py
+++ b/django/contrib/auth/models.py
@@ -16,6 +16,7 @@ from django.contrib.auth.hashers import (
check_password, make_password, is_password_usable, UNUSABLE_PASSWORD)
from django.contrib.auth.signals import user_logged_in
from django.contrib.contenttypes.models import ContentType
+from django.utils.encoding import python_2_unicode_compatible
def update_last_login(sender, user, **kwargs):
@@ -41,6 +42,7 @@ class PermissionManager(models.Manager):
)
+@python_2_unicode_compatible
class Permission(models.Model):
"""
The permissions system provides a way to assign permissions to specific
@@ -76,7 +78,7 @@ class Permission(models.Model):
ordering = ('content_type__app_label', 'content_type__model',
'codename')
- def __unicode__(self):
+ def __str__(self):
return "%s | %s | %s" % (
six.text_type(self.content_type.app_label),
six.text_type(self.content_type),
@@ -94,6 +96,7 @@ class GroupManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name)
+@python_2_unicode_compatible
class Group(models.Model):
"""
Groups are a generic way of categorizing users to apply permissions, or
@@ -121,7 +124,7 @@ class Group(models.Model):
verbose_name = _('group')
verbose_name_plural = _('groups')
- def __unicode__(self):
+ def __str__(self):
return self.name
def natural_key(self):
@@ -221,6 +224,7 @@ def _user_has_module_perms(user, app_label):
return False
+@python_2_unicode_compatible
class User(models.Model):
"""
Users within the Django authentication system are represented by this
@@ -259,7 +263,7 @@ class User(models.Model):
verbose_name = _('user')
verbose_name_plural = _('users')
- def __unicode__(self):
+ def __str__(self):
return self.username
def natural_key(self):
@@ -403,6 +407,7 @@ class User(models.Model):
return self._profile_cache
+@python_2_unicode_compatible
class AnonymousUser(object):
id = None
pk = None
@@ -416,7 +421,7 @@ class AnonymousUser(object):
def __init__(self):
pass
- def __unicode__(self):
+ def __str__(self):
return 'AnonymousUser'
def __eq__(self, other):
diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py
index 475b3c8dea..b043b4187a 100644
--- a/django/contrib/comments/models.py
+++ b/django/contrib/comments/models.py
@@ -8,6 +8,7 @@ from django.core import urlresolvers
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django.conf import settings
+from django.utils.encoding import python_2_unicode_compatible
COMMENT_MAX_LENGTH = getattr(settings,'COMMENT_MAX_LENGTH',3000)
@@ -39,6 +40,7 @@ class BaseCommentAbstractModel(models.Model):
args=(self.content_type_id, self.object_pk)
)
+@python_2_unicode_compatible
class Comment(BaseCommentAbstractModel):
"""
A user comment about some object.
@@ -76,7 +78,7 @@ class Comment(BaseCommentAbstractModel):
verbose_name = _('comment')
verbose_name_plural = _('comments')
- def __unicode__(self):
+ def __str__(self):
return "%s: %s..." % (self.name, self.comment[:50])
def save(self, *args, **kwargs):
@@ -153,6 +155,7 @@ class Comment(BaseCommentAbstractModel):
}
return _('Posted by %(user)s at %(date)s\n\n%(comment)s\n\nhttp://%(domain)s%(url)s') % d
+@python_2_unicode_compatible
class CommentFlag(models.Model):
"""
Records a flag on a comment. This is intentionally flexible; right now, a
@@ -182,7 +185,7 @@ class CommentFlag(models.Model):
verbose_name = _('comment flag')
verbose_name_plural = _('comment flags')
- def __unicode__(self):
+ def __str__(self):
return "%s flag of comment ID %s by %s" % \
(self.flag, self.comment_id, self.user.username)
diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py
index e6d547a491..b658655bbb 100644
--- a/django/contrib/contenttypes/models.py
+++ b/django/contrib/contenttypes/models.py
@@ -1,6 +1,7 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_text, force_text
+from django.utils.encoding import python_2_unicode_compatible
class ContentTypeManager(models.Manager):
@@ -122,6 +123,7 @@ class ContentTypeManager(models.Manager):
self.__class__._cache.setdefault(using, {})[key] = ct
self.__class__._cache.setdefault(using, {})[ct.id] = ct
+@python_2_unicode_compatible
class ContentType(models.Model):
name = models.CharField(max_length=100)
app_label = models.CharField(max_length=100)
@@ -135,7 +137,7 @@ class ContentType(models.Model):
ordering = ('name',)
unique_together = (('app_label', 'model'),)
- def __unicode__(self):
+ def __str__(self):
# self.name is deprecated in favor of using model's verbose_name, which
# can be translated. Formal deprecation is delayed until we have DB
# migration to be able to remove the field from the database along with
diff --git a/django/contrib/contenttypes/tests.py b/django/contrib/contenttypes/tests.py
index cfd7e6ff32..2f92a34581 100644
--- a/django/contrib/contenttypes/tests.py
+++ b/django/contrib/contenttypes/tests.py
@@ -8,6 +8,7 @@ from django.http import HttpRequest, Http404
from django.test import TestCase
from django.utils.http import urlquote
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
class ConcreteModel(models.Model):
@@ -17,13 +18,14 @@ class ProxyModel(ConcreteModel):
class Meta:
proxy = True
+@python_2_unicode_compatible
class FooWithoutUrl(models.Model):
"""
Fake model not defining ``get_absolute_url`` for
:meth:`ContentTypesTests.test_shortcut_view_without_get_absolute_url`"""
name = models.CharField(max_length=30, unique=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/django/contrib/databrowse/datastructures.py b/django/contrib/databrowse/datastructures.py
index e48383f438..13e24167f5 100644
--- a/django/contrib/databrowse/datastructures.py
+++ b/django/contrib/databrowse/datastructures.py
@@ -9,6 +9,7 @@ from django.utils import formats
from django.utils.text import capfirst
from django.utils.encoding import smart_text, smart_bytes, iri_to_uri
from django.db.models.query import QuerySet
+from django.utils.encoding import python_2_unicode_compatible
EMPTY_VALUE = '(None)'
DISPLAY_SIZE = 100
@@ -84,6 +85,7 @@ class EasyChoice(object):
def url(self):
return '%s%s/%s/%s/%s/' % (self.model.site.root_url, self.model.model._meta.app_label, self.model.model._meta.module_name, self.field.field.name, iri_to_uri(self.value))
+@python_2_unicode_compatible
class EasyInstance(object):
def __init__(self, easy_model, instance):
self.model, self.instance = easy_model, instance
@@ -91,7 +93,7 @@ class EasyInstance(object):
def __repr__(self):
return smart_bytes('<EasyInstance for %s (%s)>' % (self.model.model._meta.object_name, self.instance._get_pk_val()))
- def __unicode__(self):
+ def __str__(self):
val = smart_text(self.instance)
if len(val) > DISPLAY_SIZE:
return val[:DISPLAY_SIZE] + '...'
diff --git a/django/contrib/databrowse/tests.py b/django/contrib/databrowse/tests.py
index 149383cf72..d649b4af67 100644
--- a/django/contrib/databrowse/tests.py
+++ b/django/contrib/databrowse/tests.py
@@ -1,26 +1,30 @@
from django.contrib import databrowse
from django.db import models
from django.test import TestCase
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class SomeModel(models.Model):
some_field = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.some_field
+@python_2_unicode_compatible
class SomeOtherModel(models.Model):
some_other_field = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.some_other_field
+@python_2_unicode_compatible
class YetAnotherModel(models.Model):
yet_another_field = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.yet_another_field
diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py
index 42ec155f34..3a5b4d6135 100644
--- a/django/contrib/flatpages/models.py
+++ b/django/contrib/flatpages/models.py
@@ -3,8 +3,10 @@ from __future__ import unicode_literals
from django.db import models
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class FlatPage(models.Model):
url = models.CharField(_('URL'), max_length=100, db_index=True)
title = models.CharField(_('title'), max_length=200)
@@ -21,7 +23,7 @@ class FlatPage(models.Model):
verbose_name_plural = _('flat pages')
ordering = ('url',)
- def __unicode__(self):
+ def __str__(self):
return "%s -- %s" % (self.url, self.title)
def get_absolute_url(self):
diff --git a/django/contrib/gis/db/backends/base.py b/django/contrib/gis/db/backends/base.py
index d9f3546cff..f7af420a8d 100644
--- a/django/contrib/gis/db/backends/base.py
+++ b/django/contrib/gis/db/backends/base.py
@@ -5,6 +5,7 @@ Base/mixin classes for the spatial backend database operations and the
import re
from django.contrib.gis import gdal
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
class BaseSpatialOperations(object):
"""
@@ -131,6 +132,7 @@ class BaseSpatialOperations(object):
def spatial_ref_sys(self):
raise NotImplementedError
+@python_2_unicode_compatible
class SpatialRefSysMixin(object):
"""
The SpatialRefSysMixin is a class used by the database-dependent
@@ -325,7 +327,7 @@ class SpatialRefSysMixin(object):
radius, flattening = sphere_params
return 'SPHEROID["%s",%s,%s]' % (sphere_name, radius, flattening)
- def __unicode__(self):
+ def __str__(self):
"""
Returns the string representation. If GDAL is installed,
it will be 'pretty' OGC WKT.
diff --git a/django/contrib/gis/db/backends/oracle/models.py b/django/contrib/gis/db/backends/oracle/models.py
index ed29f7bb38..b7deb3a946 100644
--- a/django/contrib/gis/db/backends/oracle/models.py
+++ b/django/contrib/gis/db/backends/oracle/models.py
@@ -9,7 +9,9 @@
"""
from django.contrib.gis.db import models
from django.contrib.gis.db.backends.base import SpatialRefSysMixin
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class GeometryColumns(models.Model):
"Maps to the Oracle USER_SDO_GEOM_METADATA table."
table_name = models.CharField(max_length=32)
@@ -36,7 +38,7 @@ class GeometryColumns(models.Model):
"""
return 'column_name'
- def __unicode__(self):
+ def __str__(self):
return '%s - %s (SRID: %s)' % (self.table_name, self.column_name, self.srid)
class SpatialRefSys(models.Model, SpatialRefSysMixin):
diff --git a/django/contrib/gis/db/backends/postgis/models.py b/django/contrib/gis/db/backends/postgis/models.py
index a38598343c..e8052594c6 100644
--- a/django/contrib/gis/db/backends/postgis/models.py
+++ b/django/contrib/gis/db/backends/postgis/models.py
@@ -3,7 +3,9 @@
"""
from django.db import models
from django.contrib.gis.db.backends.base import SpatialRefSysMixin
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class GeometryColumns(models.Model):
"""
The 'geometry_columns' table from the PostGIS. See the PostGIS
@@ -37,7 +39,7 @@ class GeometryColumns(models.Model):
"""
return 'f_geometry_column'
- def __unicode__(self):
+ def __str__(self):
return "%s.%s - %dD %s field (SRID: %d)" % \
(self.f_table_name, self.f_geometry_column,
self.coord_dimension, self.type, self.srid)
diff --git a/django/contrib/gis/db/backends/spatialite/models.py b/django/contrib/gis/db/backends/spatialite/models.py
index 684c5d8fc7..b281f0bc62 100644
--- a/django/contrib/gis/db/backends/spatialite/models.py
+++ b/django/contrib/gis/db/backends/spatialite/models.py
@@ -3,7 +3,9 @@
"""
from django.db import models
from django.contrib.gis.db.backends.base import SpatialRefSysMixin
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class GeometryColumns(models.Model):
"""
The 'geometry_columns' table from SpatiaLite.
@@ -35,7 +37,7 @@ class GeometryColumns(models.Model):
"""
return 'f_geometry_column'
- def __unicode__(self):
+ def __str__(self):
return "%s.%s - %dD %s field (SRID: %d)" % \
(self.f_table_name, self.f_geometry_column,
self.coord_dimension, self.type, self.srid)
diff --git a/django/contrib/gis/maps/google/overlays.py b/django/contrib/gis/maps/google/overlays.py
index 28603ac422..b82d967da6 100644
--- a/django/contrib/gis/maps/google/overlays.py
+++ b/django/contrib/gis/maps/google/overlays.py
@@ -2,8 +2,10 @@ from django.contrib.gis.geos import fromstr, Point, LineString, LinearRing, Poly
from django.utils.functional import total_ordering
from django.utils.safestring import mark_safe
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class GEvent(object):
"""
A Python wrapper for the Google GEvent object.
@@ -48,10 +50,11 @@ class GEvent(object):
self.event = event
self.action = action
- def __unicode__(self):
+ def __str__(self):
"Returns the parameter part of a GEvent."
return mark_safe('"%s", %s' %(self.event, self.action))
+@python_2_unicode_compatible
class GOverlayBase(object):
def __init__(self):
self.events = []
@@ -64,7 +67,7 @@ class GOverlayBase(object):
"Attaches a GEvent to the overlay object."
self.events.append(event)
- def __unicode__(self):
+ def __str__(self):
"The string representation is the JavaScript API call."
return mark_safe('%s(%s)' % (self.__class__.__name__, self.js_params))
diff --git a/django/contrib/gis/tests/distapp/models.py b/django/contrib/gis/tests/distapp/models.py
index 76e7d3a03f..bf08829eae 100644
--- a/django/contrib/gis/tests/distapp/models.py
+++ b/django/contrib/gis/tests/distapp/models.py
@@ -1,50 +1,58 @@
from django.contrib.gis.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class SouthTexasCity(models.Model):
"City model on projected coordinate system for South Texas."
name = models.CharField(max_length=30)
point = models.PointField(srid=32140)
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
+@python_2_unicode_compatible
class SouthTexasCityFt(models.Model):
"Same City model as above, but U.S. survey feet are the units."
name = models.CharField(max_length=30)
point = models.PointField(srid=2278)
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
+@python_2_unicode_compatible
class AustraliaCity(models.Model):
"City model for Australia, using WGS84."
name = models.CharField(max_length=30)
point = models.PointField()
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
+@python_2_unicode_compatible
class CensusZipcode(models.Model):
"Model for a few South Texas ZIP codes (in original Census NAD83)."
name = models.CharField(max_length=5)
poly = models.PolygonField(srid=4269)
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
+@python_2_unicode_compatible
class SouthTexasZipcode(models.Model):
"Model for a few South Texas ZIP codes."
name = models.CharField(max_length=5)
poly = models.PolygonField(srid=32140, null=True)
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
+@python_2_unicode_compatible
class Interstate(models.Model):
"Geodetic model for U.S. Interstates."
name = models.CharField(max_length=10)
path = models.LineStringField()
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
+@python_2_unicode_compatible
class SouthTexasInterstate(models.Model):
"Projected model for South Texas Interstates."
name = models.CharField(max_length=10)
path = models.LineStringField(srid=32140)
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
diff --git a/django/contrib/gis/tests/geo3d/models.py b/django/contrib/gis/tests/geo3d/models.py
index 3c4f77ee05..81e5f55f78 100644
--- a/django/contrib/gis/tests/geo3d/models.py
+++ b/django/contrib/gis/tests/geo3d/models.py
@@ -1,59 +1,67 @@
from django.contrib.gis.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class City3D(models.Model):
name = models.CharField(max_length=30)
point = models.PointField(dim=3)
objects = models.GeoManager()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Interstate2D(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField(srid=4269)
objects = models.GeoManager()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Interstate3D(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField(dim=3, srid=4269)
objects = models.GeoManager()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class InterstateProj2D(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField(srid=32140)
objects = models.GeoManager()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class InterstateProj3D(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField(dim=3, srid=32140)
objects = models.GeoManager()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Polygon2D(models.Model):
name = models.CharField(max_length=30)
poly = models.PolygonField(srid=32140)
objects = models.GeoManager()
-
- def __unicode__(self):
+
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Polygon3D(models.Model):
name = models.CharField(max_length=30)
poly = models.PolygonField(dim=3, srid=32140)
objects = models.GeoManager()
-
- def __unicode__(self):
+
+ def __str__(self):
return self.name
class Point2D(models.Model):
diff --git a/django/contrib/gis/tests/geoadmin/models.py b/django/contrib/gis/tests/geoadmin/models.py
index 51a76d1a0e..af0898823d 100644
--- a/django/contrib/gis/tests/geoadmin/models.py
+++ b/django/contrib/gis/tests/geoadmin/models.py
@@ -1,10 +1,12 @@
from django.contrib.gis.db import models
from django.contrib.gis import admin
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=30)
point = models.PointField()
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
admin.site.register(City, admin.OSMGeoAdmin)
diff --git a/django/contrib/gis/tests/geoapp/models.py b/django/contrib/gis/tests/geoapp/models.py
index 79061e1cfc..abde509c8b 100644
--- a/django/contrib/gis/tests/geoapp/models.py
+++ b/django/contrib/gis/tests/geoapp/models.py
@@ -1,20 +1,23 @@
from django.contrib.gis.db import models
from django.contrib.gis.tests.utils import mysql, spatialite
+from django.utils.encoding import python_2_unicode_compatible
# MySQL spatial indices can't handle NULL geometries.
null_flag = not mysql
+@python_2_unicode_compatible
class Country(models.Model):
name = models.CharField(max_length=30)
mpoly = models.MultiPolygonField() # SRID, by default, is 4326
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
+@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=30)
point = models.PointField()
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
# This is an inherited model from City
class PennsylvaniaCity(City):
@@ -22,28 +25,31 @@ class PennsylvaniaCity(City):
founded = models.DateTimeField(null=True)
objects = models.GeoManager() # TODO: This should be implicitly inherited.
+@python_2_unicode_compatible
class State(models.Model):
name = models.CharField(max_length=30)
poly = models.PolygonField(null=null_flag) # Allowing NULL geometries here.
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
+@python_2_unicode_compatible
class Track(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField()
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
class Truth(models.Model):
val = models.BooleanField()
objects = models.GeoManager()
if not spatialite:
+ @python_2_unicode_compatible
class Feature(models.Model):
name = models.CharField(max_length=20)
geom = models.GeometryField()
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
class MinusOneSRID(models.Model):
geom = models.PointField(srid=-1) # Minus one SRID.
diff --git a/django/contrib/gis/tests/geogapp/models.py b/django/contrib/gis/tests/geogapp/models.py
index 3696ba2ff4..7e802f9321 100644
--- a/django/contrib/gis/tests/geogapp/models.py
+++ b/django/contrib/gis/tests/geogapp/models.py
@@ -1,20 +1,24 @@
from django.contrib.gis.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=30)
point = models.PointField(geography=True)
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
+@python_2_unicode_compatible
class Zipcode(models.Model):
code = models.CharField(max_length=10)
poly = models.PolygonField(geography=True)
objects = models.GeoManager()
- def __unicode__(self): return self.code
+ def __str__(self): return self.code
+@python_2_unicode_compatible
class County(models.Model):
name = models.CharField(max_length=25)
state = models.CharField(max_length=20)
mpoly = models.MultiPolygonField(geography=True)
objects = models.GeoManager()
- def __unicode__(self): return ' County, '.join([self.name, self.state])
+ def __str__(self): return ' County, '.join([self.name, self.state])
diff --git a/django/contrib/gis/tests/relatedapp/models.py b/django/contrib/gis/tests/relatedapp/models.py
index aec4e15749..659fef7a93 100644
--- a/django/contrib/gis/tests/relatedapp/models.py
+++ b/django/contrib/gis/tests/relatedapp/models.py
@@ -1,37 +1,41 @@
from django.contrib.gis.db import models
from django.contrib.localflavor.us.models import USStateField
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Location(models.Model):
point = models.PointField()
objects = models.GeoManager()
- def __unicode__(self): return self.point.wkt
+ def __str__(self): return self.point.wkt
+@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=50)
state = USStateField()
location = models.ForeignKey(Location)
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
class AugmentedLocation(Location):
extra_text = models.TextField(blank=True)
objects = models.GeoManager()
-
+
class DirectoryEntry(models.Model):
listing_text = models.CharField(max_length=50)
location = models.ForeignKey(AugmentedLocation)
objects = models.GeoManager()
+@python_2_unicode_compatible
class Parcel(models.Model):
name = models.CharField(max_length=30)
city = models.ForeignKey(City)
center1 = models.PointField()
# Throwing a curveball w/`db_column` here.
- center2 = models.PointField(srid=2276, db_column='mycenter')
+ center2 = models.PointField(srid=2276, db_column='mycenter')
border1 = models.PolygonField()
border2 = models.PolygonField(srid=2276)
objects = models.GeoManager()
- def __unicode__(self): return self.name
+ def __str__(self): return self.name
# These use the GeoManager but do not have any geographic fields.
class Author(models.Model):
diff --git a/django/contrib/gis/utils/ogrinspect.py b/django/contrib/gis/utils/ogrinspect.py
index f8977059d9..4266ee4b4c 100644
--- a/django/contrib/gis/utils/ogrinspect.py
+++ b/django/contrib/gis/utils/ogrinspect.py
@@ -223,4 +223,4 @@ def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non
if name_field:
yield ''
- yield ' def __unicode__(self): return self.%s' % name_field
+ yield ' def __str__(self): return self.%s' % name_field
diff --git a/django/contrib/messages/storage/base.py b/django/contrib/messages/storage/base.py
index 5433bbff28..7fe8a077ed 100644
--- a/django/contrib/messages/storage/base.py
+++ b/django/contrib/messages/storage/base.py
@@ -1,14 +1,15 @@
from __future__ import unicode_literals
from django.conf import settings
-from django.utils.encoding import force_text, StrAndUnicode
+from django.utils.encoding import force_text, python_2_unicode_compatible
from django.contrib.messages import constants, utils
LEVEL_TAGS = utils.get_level_tags()
-class Message(StrAndUnicode):
+@python_2_unicode_compatible
+class Message(object):
"""
Represents an actual message that can be stored in any of the supported
storage classes (typically session- or cookie-based) and rendered in a view
@@ -35,7 +36,7 @@ class Message(StrAndUnicode):
return isinstance(other, Message) and self.level == other.level and \
self.message == other.message
- def __unicode__(self):
+ def __str__(self):
return force_text(self.message)
def _get_tags(self):
diff --git a/django/contrib/redirects/models.py b/django/contrib/redirects/models.py
index 4233d55793..a0376b5578 100644
--- a/django/contrib/redirects/models.py
+++ b/django/contrib/redirects/models.py
@@ -1,7 +1,9 @@
from django.db import models
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Redirect(models.Model):
site = models.ForeignKey(Site)
old_path = models.CharField(_('redirect from'), max_length=200, db_index=True,
@@ -15,6 +17,6 @@ class Redirect(models.Model):
db_table = 'django_redirect'
unique_together=(('site', 'old_path'),)
ordering = ('old_path',)
-
- def __unicode__(self):
+
+ def __str__(self):
return "%s ---> %s" % (self.old_path, self.new_path)
diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py
index fecbff79d8..8590740658 100644
--- a/django/contrib/sites/models.py
+++ b/django/contrib/sites/models.py
@@ -1,5 +1,6 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
+from django.utils.encoding import python_2_unicode_compatible
SITE_CACHE = {}
@@ -32,6 +33,7 @@ class SiteManager(models.Manager):
SITE_CACHE = {}
+@python_2_unicode_compatible
class Site(models.Model):
domain = models.CharField(_('domain name'), max_length=100)
@@ -44,7 +46,7 @@ class Site(models.Model):
verbose_name_plural = _('sites')
ordering = ('domain',)
- def __unicode__(self):
+ def __str__(self):
return self.domain
def save(self, *args, **kwargs):
@@ -62,6 +64,7 @@ class Site(models.Model):
pass
+@python_2_unicode_compatible
class RequestSite(object):
"""
A class that shares the primary interface of Site (i.e., it has
@@ -73,7 +76,7 @@ class RequestSite(object):
def __init__(self, request):
self.domain = self.name = request.get_host()
- def __unicode__(self):
+ def __str__(self):
return self.domain
def save(self, force_insert=False, force_update=False):
diff --git a/django/core/files/base.py b/django/core/files/base.py
index 4ad0be4fd8..d7a8cb8539 100644
--- a/django/core/files/base.py
+++ b/django/core/files/base.py
@@ -5,7 +5,9 @@ from io import BytesIO
from django.utils.encoding import smart_bytes, smart_text
from django.core.files.utils import FileProxyMixin
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class File(FileProxyMixin):
DEFAULT_CHUNK_SIZE = 64 * 2**10
@@ -17,7 +19,7 @@ class File(FileProxyMixin):
if hasattr(file, 'mode'):
self.mode = file.mode
- def __unicode__(self):
+ def __str__(self):
return smart_text(self.name or '')
def __repr__(self):
@@ -121,6 +123,7 @@ class File(FileProxyMixin):
def close(self):
self.file.close()
+@python_2_unicode_compatible
class ContentFile(File):
"""
A File-like object that takes just raw content, rather than an actual file.
@@ -130,7 +133,7 @@ class ContentFile(File):
super(ContentFile, self).__init__(BytesIO(content), name=name)
self.size = len(content)
- def __unicode__(self):
+ def __str__(self):
return 'Raw content'
def __bool__(self):
diff --git a/django/core/files/uploadhandler.py b/django/core/files/uploadhandler.py
index 68d540e595..c422945d6f 100644
--- a/django/core/files/uploadhandler.py
+++ b/django/core/files/uploadhandler.py
@@ -10,6 +10,7 @@ from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.files.uploadedfile import TemporaryUploadedFile, InMemoryUploadedFile
from django.utils import importlib
+from django.utils.encoding import python_2_unicode_compatible
__all__ = ['UploadFileException','StopUpload', 'SkipFile', 'FileUploadHandler',
'TemporaryFileUploadHandler', 'MemoryFileUploadHandler',
@@ -21,6 +22,7 @@ class UploadFileException(Exception):
"""
pass
+@python_2_unicode_compatible
class StopUpload(UploadFileException):
"""
This exception is raised when an upload must abort.
@@ -33,7 +35,7 @@ class StopUpload(UploadFileException):
"""
self.connection_reset = connection_reset
- def __unicode__(self):
+ def __str__(self):
if self.connection_reset:
return 'StopUpload: Halt current upload.'
else:
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 9211a76b68..014b8bf359 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -13,6 +13,7 @@ from django.utils.translation import activate, deactivate_all, get_language, str
from django.utils.encoding import force_text, smart_text
from django.utils.datastructures import SortedDict
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
# Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces".
get_verbose_name = lambda class_name: re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', ' \\1', class_name).lower().strip()
@@ -22,6 +23,7 @@ DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering',
'order_with_respect_to', 'app_label', 'db_tablespace',
'abstract', 'managed', 'proxy', 'auto_created')
+@python_2_unicode_compatible
class Options(object):
def __init__(self, meta, app_label=None):
self.local_fields, self.local_many_to_many = [], []
@@ -200,7 +202,7 @@ class Options(object):
def __repr__(self):
return '<Options for %s>' % self.object_name
- def __unicode__(self):
+ def __str__(self):
return "%s.%s" % (smart_text(self.app_label), smart_text(self.module_name))
def verbose_name_raw(self):
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 45b758202a..3299c2becc 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -12,7 +12,7 @@ from django.forms.util import flatatt, ErrorDict, ErrorList
from django.forms.widgets import Media, media_property, TextInput, Textarea
from django.utils.datastructures import SortedDict
from django.utils.html import conditional_escape, format_html
-from django.utils.encoding import StrAndUnicode, smart_text, force_text
+from django.utils.encoding import smart_text, force_text, python_2_unicode_compatible
from django.utils.safestring import mark_safe
from django.utils import six
@@ -68,7 +68,8 @@ class DeclarativeFieldsMetaclass(type):
new_class.media = media_property(new_class)
return new_class
-class BaseForm(StrAndUnicode):
+@python_2_unicode_compatible
+class BaseForm(object):
# This is the main implementation of all the Form logic. Note that this
# class is different than Form. See the comments by the Form class for more
# information. Any improvements to the form API should be made to *this*
@@ -95,7 +96,7 @@ class BaseForm(StrAndUnicode):
# self.base_fields.
self.fields = copy.deepcopy(self.base_fields)
- def __unicode__(self):
+ def __str__(self):
return self.as_table()
def __iter__(self):
@@ -387,7 +388,8 @@ class Form(six.with_metaclass(DeclarativeFieldsMetaclass, BaseForm)):
# to define a form using declarative syntax.
# BaseForm itself has no way of designating self.fields.
-class BoundField(StrAndUnicode):
+@python_2_unicode_compatible
+class BoundField(object):
"A Field plus data"
def __init__(self, form, field, name):
self.form = form
@@ -402,7 +404,7 @@ class BoundField(StrAndUnicode):
self.label = self.field.label
self.help_text = field.help_text or ''
- def __unicode__(self):
+ def __str__(self):
"""Renders this field as an HTML widget."""
if self.field.show_hidden_initial:
return self.as_widget() + self.as_hidden(only_initial=True)
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index 4ea8dc4ca9..258c673da8 100644
--- a/django/forms/formsets.py
+++ b/django/forms/formsets.py
@@ -5,7 +5,7 @@ from django.forms import Form
from django.forms.fields import IntegerField, BooleanField
from django.forms.util import ErrorList
from django.forms.widgets import Media, HiddenInput
-from django.utils.encoding import StrAndUnicode
+from django.utils.encoding import python_2_unicode_compatible
from django.utils.safestring import mark_safe
from django.utils import six
from django.utils.six.moves import xrange
@@ -33,7 +33,8 @@ class ManagementForm(Form):
self.base_fields[MAX_NUM_FORM_COUNT] = IntegerField(required=False, widget=HiddenInput)
super(ManagementForm, self).__init__(*args, **kwargs)
-class BaseFormSet(StrAndUnicode):
+@python_2_unicode_compatible
+class BaseFormSet(object):
"""
A collection of instances of the same Form class.
"""
@@ -51,7 +52,7 @@ class BaseFormSet(StrAndUnicode):
# construct the forms in the formset
self._construct_forms()
- def __unicode__(self):
+ def __str__(self):
return self.as_table()
def __iter__(self):
diff --git a/django/forms/util.py b/django/forms/util.py
index cd6b52df6f..9b1bcebe33 100644
--- a/django/forms/util.py
+++ b/django/forms/util.py
@@ -2,7 +2,7 @@ from __future__ import unicode_literals
from django.conf import settings
from django.utils.html import format_html, format_html_join
-from django.utils.encoding import StrAndUnicode, force_text
+from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.safestring import mark_safe
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
@@ -22,13 +22,14 @@ def flatatt(attrs):
"""
return format_html_join('', ' {0}="{1}"', attrs.items())
-class ErrorDict(dict, StrAndUnicode):
+@python_2_unicode_compatible
+class ErrorDict(dict):
"""
A collection of errors that knows how to display itself in various formats.
The dictionary keys are the field names, and the values are the errors.
"""
- def __unicode__(self):
+ def __str__(self):
return self.as_ul()
def as_ul(self):
@@ -42,11 +43,12 @@ class ErrorDict(dict, StrAndUnicode):
def as_text(self):
return '\n'.join(['* %s\n%s' % (k, '\n'.join([' * %s' % force_text(i) for i in v])) for k, v in self.items()])
-class ErrorList(list, StrAndUnicode):
+@python_2_unicode_compatible
+class ErrorList(list):
"""
A collection of errors that knows how to display itself in various formats.
"""
- def __unicode__(self):
+ def __str__(self):
return self.as_ul()
def as_ul(self):
diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index be9ac8eb8f..fe7c06ff34 100644
--- a/django/forms/widgets.py
+++ b/django/forms/widgets.py
@@ -17,7 +17,7 @@ from django.forms.util import flatatt, to_current_timezone
from django.utils.datastructures import MultiValueDict, MergeDict
from django.utils.html import conditional_escape, format_html, format_html_join
from django.utils.translation import ugettext, ugettext_lazy
-from django.utils.encoding import StrAndUnicode, force_text
+from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.safestring import mark_safe
from django.utils import six
from django.utils import datetime_safe, formats
@@ -34,7 +34,8 @@ __all__ = (
MEDIA_TYPES = ('css','js')
-class Media(StrAndUnicode):
+@python_2_unicode_compatible
+class Media(object):
def __init__(self, media=None, **kwargs):
if media:
media_attrs = media.__dict__
@@ -51,7 +52,7 @@ class Media(StrAndUnicode):
# if media_attrs != {}:
# raise TypeError("'class Media' has invalid attribute(s): %s" % ','.join(media_attrs.keys()))
- def __unicode__(self):
+ def __str__(self):
return self.render()
def render(self):
@@ -142,7 +143,8 @@ class MediaDefiningClass(type):
new_class.media = media_property(new_class)
return new_class
-class SubWidget(StrAndUnicode):
+@python_2_unicode_compatible
+class SubWidget(object):
"""
Some widgets are made of multiple HTML elements -- namely, RadioSelect.
This is a class that represents the "inner" HTML element of a widget.
@@ -152,7 +154,7 @@ class SubWidget(StrAndUnicode):
self.name, self.value = name, value
self.attrs, self.choices = attrs, choices
- def __unicode__(self):
+ def __str__(self):
args = [self.name, self.value, self.attrs]
if self.choices:
args.append(self.choices)
@@ -647,6 +649,7 @@ class SelectMultiple(Select):
data_set = set([force_text(value) for value in data])
return data_set != initial_set
+@python_2_unicode_compatible
class RadioInput(SubWidget):
"""
An object used by RadioFieldRenderer that represents a single
@@ -660,7 +663,7 @@ class RadioInput(SubWidget):
self.choice_label = force_text(choice[1])
self.index = index
- def __unicode__(self):
+ def __str__(self):
return self.render()
def render(self, name=None, value=None, attrs=None, choices=()):
@@ -685,7 +688,8 @@ class RadioInput(SubWidget):
final_attrs['checked'] = 'checked'
return format_html('<input{0} />', flatatt(final_attrs))
-class RadioFieldRenderer(StrAndUnicode):
+@python_2_unicode_compatible
+class RadioFieldRenderer(object):
"""
An object used by RadioSelect to enable customization of radio widgets.
"""
@@ -702,7 +706,7 @@ class RadioFieldRenderer(StrAndUnicode):
choice = self.choices[idx] # Let the IndexError propogate
return RadioInput(self.name, self.value, self.attrs.copy(), choice, idx)
- def __unicode__(self):
+ def __str__(self):
return self.render()
def render(self):
diff --git a/django/template/base.py b/django/template/base.py
index 4dcba6dd2b..24ad9320e0 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -20,6 +20,7 @@ from django.utils.html import escape
from django.utils.module_loading import module_has_submodule
from django.utils import six
from django.utils.timezone import template_localtime
+from django.utils.encoding import python_2_unicode_compatible
TOKEN_TEXT = 0
@@ -79,13 +80,14 @@ class TemplateDoesNotExist(Exception):
class TemplateEncodingError(Exception):
pass
+@python_2_unicode_compatible
class VariableDoesNotExist(Exception):
def __init__(self, msg, params=()):
self.msg = msg
self.params = params
- def __unicode__(self):
+ def __str__(self):
return self.msg % tuple([force_text(p, errors='replace')
for p in self.params])
diff --git a/django/test/html.py b/django/test/html.py
index acdb4ffd14..274810cab4 100644
--- a/django/test/html.py
+++ b/django/test/html.py
@@ -8,6 +8,7 @@ import re
from django.utils.encoding import force_text
from django.utils.html_parser import HTMLParser, HTMLParseError
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
WHITESPACE = re.compile('\s+')
@@ -17,6 +18,7 @@ def normalize_whitespace(string):
return WHITESPACE.sub(' ', string)
+@python_2_unicode_compatible
class Element(object):
def __init__(self, name, attributes):
self.name = name
@@ -117,7 +119,7 @@ class Element(object):
def __getitem__(self, key):
return self.children[key]
- def __unicode__(self):
+ def __str__(self):
output = '<%s' % self.name
for key, value in self.attributes:
if value:
@@ -136,11 +138,12 @@ class Element(object):
return six.text_type(self)
+@python_2_unicode_compatible
class RootElement(Element):
def __init__(self):
super(RootElement, self).__init__(None, ())
- def __unicode__(self):
+ def __str__(self):
return ''.join(six.text_type(c) for c in self.children)
diff --git a/tests/modeltests/aggregation/models.py b/tests/modeltests/aggregation/models.py
index ccc12898b7..b4f797ee03 100644
--- a/tests/modeltests/aggregation/models.py
+++ b/tests/modeltests/aggregation/models.py
@@ -1,22 +1,26 @@
# coding: utf-8
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()
friends = models.ManyToManyField('self', blank=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Publisher(models.Model):
name = models.CharField(max_length=255)
num_awards = models.IntegerField()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Book(models.Model):
isbn = models.CharField(max_length=9)
name = models.CharField(max_length=255)
@@ -28,15 +32,16 @@ class Book(models.Model):
publisher = models.ForeignKey(Publisher)
pubdate = models.DateField()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Store(models.Model):
name = models.CharField(max_length=255)
books = models.ManyToManyField(Book)
original_opening = models.DateTimeField()
friday_night_closing = models.TimeField()
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py
index 06aa9cf3c3..660beddf49 100644
--- a/tests/modeltests/basic/models.py
+++ b/tests/modeltests/basic/models.py
@@ -5,8 +5,10 @@
This is a basic model with only two non-primary-key fields.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
@@ -14,5 +16,5 @@ class Article(models.Model):
class Meta:
ordering = ('pub_date','headline')
- def __unicode__(self):
+ def __str__(self):
return self.headline
diff --git a/tests/modeltests/choices/models.py b/tests/modeltests/choices/models.py
index ee01911573..2fa33a9680 100644
--- a/tests/modeltests/choices/models.py
+++ b/tests/modeltests/choices/models.py
@@ -10,6 +10,7 @@ field. This method returns the "human-readable" value of the field.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
GENDER_CHOICES = (
@@ -17,9 +18,10 @@ GENDER_CHOICES = (
('F', 'Female'),
)
+@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=20)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/custom_columns/models.py b/tests/modeltests/custom_columns/models.py
index 39f1274a8f..16f0563d6b 100644
--- a/tests/modeltests/custom_columns/models.py
+++ b/tests/modeltests/custom_columns/models.py
@@ -18,24 +18,27 @@ from the default generated name, use the ``db_table`` parameter on the
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Author(models.Model):
first_name = models.CharField(max_length=30, db_column='firstname')
last_name = models.CharField(max_length=30, db_column='last')
- def __unicode__(self):
+ def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class Meta:
db_table = 'my_author_table'
ordering = ('last_name','first_name')
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
authors = models.ManyToManyField(Author, db_table='my_m2m_table')
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Meta:
diff --git a/tests/modeltests/custom_managers/models.py b/tests/modeltests/custom_managers/models.py
index a9845ad414..de7c1772ed 100644
--- a/tests/modeltests/custom_managers/models.py
+++ b/tests/modeltests/custom_managers/models.py
@@ -12,6 +12,7 @@ returns.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
# An example of a custom manager called "objects".
@@ -19,13 +20,14 @@ class PersonManager(models.Manager):
def get_fun_people(self):
return self.filter(fun=True)
+@python_2_unicode_compatible
class Person(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
fun = models.BooleanField()
objects = PersonManager()
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
# An example of a custom manager that sets get_query_set().
@@ -34,6 +36,7 @@ class PublishedBookManager(models.Manager):
def get_query_set(self):
return super(PublishedBookManager, self).get_query_set().filter(is_published=True)
+@python_2_unicode_compatible
class Book(models.Model):
title = models.CharField(max_length=50)
author = models.CharField(max_length=30)
@@ -41,7 +44,7 @@ class Book(models.Model):
published_objects = PublishedBookManager()
authors = models.ManyToManyField(Person, related_name='books')
- def __unicode__(self):
+ def __str__(self):
return self.title
# An example of providing multiple custom managers.
@@ -50,6 +53,7 @@ class FastCarManager(models.Manager):
def get_query_set(self):
return super(FastCarManager, self).get_query_set().filter(top_speed__gt=150)
+@python_2_unicode_compatible
class Car(models.Model):
name = models.CharField(max_length=10)
mileage = models.IntegerField()
@@ -57,5 +61,5 @@ class Car(models.Model):
cars = models.Manager()
fast_cars = FastCarManager()
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/custom_methods/models.py b/tests/modeltests/custom_methods/models.py
index 4e3da58851..cef3fd722b 100644
--- a/tests/modeltests/custom_methods/models.py
+++ b/tests/modeltests/custom_methods/models.py
@@ -7,13 +7,15 @@ Any method you add to a model will be available to instances.
import datetime
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateField()
- def __unicode__(self):
+ def __str__(self):
return self.headline
def was_published_today(self):
diff --git a/tests/modeltests/custom_pk/fields.py b/tests/modeltests/custom_pk/fields.py
index 68fb9dcd16..d25eeca1d5 100644
--- a/tests/modeltests/custom_pk/fields.py
+++ b/tests/modeltests/custom_pk/fields.py
@@ -3,8 +3,10 @@ import string
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class MyWrapper(object):
def __init__(self, value):
self.value = value
@@ -12,7 +14,7 @@ class MyWrapper(object):
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self.value)
- def __unicode__(self):
+ def __str__(self):
return self.value
def __eq__(self, other):
diff --git a/tests/modeltests/custom_pk/models.py b/tests/modeltests/custom_pk/models.py
index 8199b05a1a..5ef9b69f0c 100644
--- a/tests/modeltests/custom_pk/models.py
+++ b/tests/modeltests/custom_pk/models.py
@@ -11,8 +11,10 @@ from __future__ import absolute_import, unicode_literals
from django.db import models
from .fields import MyAutoField
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Employee(models.Model):
employee_code = models.IntegerField(primary_key=True, db_column = 'code')
first_name = models.CharField(max_length=20)
@@ -20,22 +22,24 @@ class Employee(models.Model):
class Meta:
ordering = ('last_name', 'first_name')
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+@python_2_unicode_compatible
class Business(models.Model):
name = models.CharField(max_length=20, primary_key=True)
employees = models.ManyToManyField(Employee)
class Meta:
verbose_name_plural = 'businesses'
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Bar(models.Model):
id = MyAutoField(primary_key=True, db_index=True)
- def __unicode__(self):
+ def __str__(self):
return repr(self.pk)
diff --git a/tests/modeltests/defer/models.py b/tests/modeltests/defer/models.py
index c64becf972..0688cbc984 100644
--- a/tests/modeltests/defer/models.py
+++ b/tests/modeltests/defer/models.py
@@ -3,18 +3,20 @@ Tests for defer() and only().
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class Secondary(models.Model):
first = models.CharField(max_length=50)
second = models.CharField(max_length=50)
+@python_2_unicode_compatible
class Primary(models.Model):
name = models.CharField(max_length=50)
value = models.CharField(max_length=50)
related = models.ForeignKey(Secondary)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Child(Primary):
diff --git a/tests/modeltests/delete/models.py b/tests/modeltests/delete/models.py
index 7e7766e824..e0cec426ea 100644
--- a/tests/modeltests/delete/models.py
+++ b/tests/modeltests/delete/models.py
@@ -1,12 +1,14 @@
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class R(models.Model):
is_default = models.BooleanField(default=False)
- def __unicode__(self):
+ def __str__(self):
return "%s" % self.pk
diff --git a/tests/modeltests/distinct_on_fields/models.py b/tests/modeltests/distinct_on_fields/models.py
index 33665e9624..7982f435d0 100644
--- a/tests/modeltests/distinct_on_fields/models.py
+++ b/tests/modeltests/distinct_on_fields/models.py
@@ -1,7 +1,9 @@
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Tag(models.Model):
name = models.CharField(max_length=10)
parent = models.ForeignKey('self', blank=True, null=True,
@@ -10,19 +12,21 @@ class Tag(models.Model):
class Meta:
ordering = ['name']
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Celebrity(models.Model):
name = models.CharField("Name", max_length=20)
greatest_fan = models.ForeignKey("Fan", null=True, unique=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Fan(models.Model):
fan_of = models.ForeignKey(Celebrity)
+@python_2_unicode_compatible
class Staff(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=50)
@@ -30,12 +34,13 @@ class Staff(models.Model):
tags = models.ManyToManyField(Tag, through='StaffTag')
coworkers = models.ManyToManyField('self')
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class StaffTag(models.Model):
staff = models.ForeignKey(Staff)
tag = models.ForeignKey(Tag)
- def __unicode__(self):
+ def __str__(self):
return "%s -> %s" % (self.tag, self.staff)
diff --git a/tests/modeltests/expressions/models.py b/tests/modeltests/expressions/models.py
index 018a0cf795..f592a0eb13 100644
--- a/tests/modeltests/expressions/models.py
+++ b/tests/modeltests/expressions/models.py
@@ -4,15 +4,18 @@ Tests for F() query expression syntax.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Employee(models.Model):
firstname = models.CharField(max_length=50)
lastname = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return '%s %s' % (self.firstname, self.lastname)
+@python_2_unicode_compatible
class Company(models.Model):
name = models.CharField(max_length=100)
num_employees = models.PositiveIntegerField()
@@ -25,5 +28,5 @@ class Company(models.Model):
related_name='company_point_of_contact_set',
null=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/field_defaults/models.py b/tests/modeltests/field_defaults/models.py
index 18840c8b4b..c99d4871cd 100644
--- a/tests/modeltests/field_defaults/models.py
+++ b/tests/modeltests/field_defaults/models.py
@@ -13,11 +13,13 @@ field.
from datetime import datetime
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField(default=datetime.now)
- def __unicode__(self):
+ def __str__(self):
return self.headline
diff --git a/tests/modeltests/field_subclassing/fields.py b/tests/modeltests/field_subclassing/fields.py
index 47d710717b..6fecbb63fc 100644
--- a/tests/modeltests/field_subclassing/fields.py
+++ b/tests/modeltests/field_subclassing/fields.py
@@ -5,8 +5,10 @@ import json
from django.db import models
from django.utils.encoding import force_text
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Small(object):
"""
A simple class to show that non-trivial Python objects can be used as
@@ -15,7 +17,7 @@ class Small(object):
def __init__(self, first, second):
self.first, self.second = first, second
- def __unicode__(self):
+ def __str__(self):
return '%s%s' % (force_text(self.first), force_text(self.second))
class SmallField(models.Field):
diff --git a/tests/modeltests/field_subclassing/models.py b/tests/modeltests/field_subclassing/models.py
index 2df9664cdc..642573cc83 100644
--- a/tests/modeltests/field_subclassing/models.py
+++ b/tests/modeltests/field_subclassing/models.py
@@ -8,13 +8,15 @@ from django.db import models
from django.utils.encoding import force_text
from .fields import SmallField, SmallerField, JSONField
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class MyModel(models.Model):
name = models.CharField(max_length=10)
data = SmallField('small field')
- def __unicode__(self):
+ def __str__(self):
return force_text(self.name)
class OtherModel(models.Model):
diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py
index 586f65e60f..8bd3501926 100644
--- a/tests/modeltests/fixtures/models.py
+++ b/tests/modeltests/fixtures/models.py
@@ -12,38 +12,43 @@ from django.contrib.auth.models import Permission
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Category(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
- def __unicode__(self):
+ def __str__(self):
return self.title
class Meta:
ordering = ('title',)
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Meta:
ordering = ('-pub_date', 'headline')
+@python_2_unicode_compatible
class Blog(models.Model):
name = models.CharField(max_length=100)
featured = models.ForeignKey(Article, related_name='fixtures_featured_set')
articles = models.ManyToManyField(Article, blank=True,
related_name='fixtures_articles_set')
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Tag(models.Model):
name = models.CharField(max_length=100)
tagged_type = models.ForeignKey(ContentType, related_name="fixtures_tag_set")
@@ -51,7 +56,7 @@ class Tag(models.Model):
tagged = generic.GenericForeignKey(ct_field='tagged_type',
fk_field='tagged_id')
- def __unicode__(self):
+ def __str__(self):
return '<%s: %s> tagged "%s"' % (self.tagged.__class__.__name__,
self.tagged, self.name)
@@ -59,10 +64,11 @@ class PersonManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name)
+@python_2_unicode_compatible
class Person(models.Model):
objects = PersonManager()
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Meta:
@@ -79,19 +85,21 @@ class Spy(Person):
objects = SpyManager()
cover_blown = models.BooleanField(default=False)
+@python_2_unicode_compatible
class Visa(models.Model):
person = models.ForeignKey(Person)
permissions = models.ManyToManyField(Permission, blank=True)
- def __unicode__(self):
+ def __str__(self):
return '%s %s' % (self.person.name,
', '.join(p.name for p in self.permissions.all()))
+@python_2_unicode_compatible
class Book(models.Model):
name = models.CharField(max_length=100)
authors = models.ManyToManyField(Person)
- def __unicode__(self):
+ def __str__(self):
authors = ' and '.join(a.name for a in self.authors.all())
return '%s by %s' % (self.name, authors) if authors else self.name
diff --git a/tests/modeltests/fixtures_model_package/models/__init__.py b/tests/modeltests/fixtures_model_package/models/__init__.py
index d309165e9c..deeba48aa9 100644
--- a/tests/modeltests/fixtures_model_package/models/__init__.py
+++ b/tests/modeltests/fixtures_model_package/models/__init__.py
@@ -1,11 +1,13 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Meta:
diff --git a/tests/modeltests/generic_relations/models.py b/tests/modeltests/generic_relations/models.py
index f2dcf7db24..2f025e660b 100644
--- a/tests/modeltests/generic_relations/models.py
+++ b/tests/modeltests/generic_relations/models.py
@@ -14,8 +14,10 @@ from __future__ import unicode_literals
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class TaggedItem(models.Model):
"""A tag on an item."""
tag = models.SlugField()
@@ -27,12 +29,13 @@ class TaggedItem(models.Model):
class Meta:
ordering = ["tag", "content_type__name"]
- def __unicode__(self):
+ def __str__(self):
return self.tag
class ValuableTaggedItem(TaggedItem):
value = models.PositiveIntegerField()
+@python_2_unicode_compatible
class Comparison(models.Model):
"""
A model that tests having multiple GenericForeignKeys
@@ -48,9 +51,10 @@ class Comparison(models.Model):
first_obj = generic.GenericForeignKey(ct_field="content_type1", fk_field="object_id1")
other_obj = generic.GenericForeignKey(ct_field="content_type2", fk_field="object_id2")
- def __unicode__(self):
+ def __str__(self):
return "%s is %s than %s" % (self.first_obj, self.comparative, self.other_obj)
+@python_2_unicode_compatible
class Animal(models.Model):
common_name = models.CharField(max_length=150)
latin_name = models.CharField(max_length=150)
@@ -60,25 +64,27 @@ class Animal(models.Model):
object_id_field="object_id1",
content_type_field="content_type1")
- def __unicode__(self):
+ def __str__(self):
return self.common_name
+@python_2_unicode_compatible
class Vegetable(models.Model):
name = models.CharField(max_length=150)
is_yucky = models.BooleanField(default=True)
tags = generic.GenericRelation(TaggedItem)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Mineral(models.Model):
name = models.CharField(max_length=150)
hardness = models.PositiveSmallIntegerField()
# note the lack of an explicit GenericRelation here...
- def __unicode__(self):
+ def __str__(self):
return self.name
class GeckoManager(models.Manager):
diff --git a/tests/modeltests/get_latest/models.py b/tests/modeltests/get_latest/models.py
index d8a690f48c..fe594dd802 100644
--- a/tests/modeltests/get_latest/models.py
+++ b/tests/modeltests/get_latest/models.py
@@ -9,8 +9,10 @@ farthest into the future."
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateField()
@@ -18,14 +20,15 @@ class Article(models.Model):
class Meta:
get_latest_by = 'pub_date'
- def __unicode__(self):
+ def __str__(self):
return self.headline
+@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=30)
birthday = models.DateField()
# Note that this model doesn't have "get_latest_by" set.
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/get_object_or_404/models.py b/tests/modeltests/get_object_or_404/models.py
index f0c73ed94a..bda060569e 100644
--- a/tests/modeltests/get_object_or_404/models.py
+++ b/tests/modeltests/get_object_or_404/models.py
@@ -11,23 +11,26 @@ performing a ``filter()`` lookup and raising a ``Http404`` exception if a
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.name
class ArticleManager(models.Manager):
def get_query_set(self):
return super(ArticleManager, self).get_query_set().filter(authors__name__icontains='sir')
+@python_2_unicode_compatible
class Article(models.Model):
authors = models.ManyToManyField(Author)
title = models.CharField(max_length=50)
objects = models.Manager()
by_a_sir = ArticleManager()
- def __unicode__(self):
+ def __str__(self):
return self.title
diff --git a/tests/modeltests/get_or_create/models.py b/tests/modeltests/get_or_create/models.py
index 78b92f09df..678f5a401c 100644
--- a/tests/modeltests/get_or_create/models.py
+++ b/tests/modeltests/get_or_create/models.py
@@ -9,14 +9,16 @@ parameters.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Person(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
birthday = models.DateField()
- def __unicode__(self):
+ def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class ManualPrimaryKeyTest(models.Model):
diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py
index b685750347..f388ddf403 100644
--- a/tests/modeltests/lookup/models.py
+++ b/tests/modeltests/lookup/models.py
@@ -8,6 +8,7 @@ from __future__ import unicode_literals
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
class Author(models.Model):
@@ -15,6 +16,7 @@ class Author(models.Model):
class Meta:
ordering = ('name', )
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateTimeField()
@@ -22,7 +24,7 @@ class Article(models.Model):
class Meta:
ordering = ('-pub_date', 'headline')
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Tag(models.Model):
@@ -31,24 +33,27 @@ class Tag(models.Model):
class Meta:
ordering = ('name', )
+@python_2_unicode_compatible
class Season(models.Model):
year = models.PositiveSmallIntegerField()
gt = models.IntegerField(null=True, blank=True)
- def __unicode__(self):
+ def __str__(self):
return six.text_type(self.year)
+@python_2_unicode_compatible
class Game(models.Model):
season = models.ForeignKey(Season, related_name='games')
home = models.CharField(max_length=100)
away = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return "%s at %s" % (self.away, self.home)
+@python_2_unicode_compatible
class Player(models.Model):
name = models.CharField(max_length=100)
games = models.ManyToManyField(Game, related_name='players')
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/m2m_and_m2o/models.py b/tests/modeltests/m2m_and_m2o/models.py
index 92ed3fbcd9..99c7b01017 100644
--- a/tests/modeltests/m2m_and_m2o/models.py
+++ b/tests/modeltests/m2m_and_m2o/models.py
@@ -7,17 +7,19 @@ from __future__ import unicode_literals
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
class User(models.Model):
username = models.CharField(max_length=20)
+@python_2_unicode_compatible
class Issue(models.Model):
num = models.IntegerField()
cc = models.ManyToManyField(User, blank=True, related_name='test_issue_cc')
client = models.ForeignKey(User, related_name='test_issue_client')
- def __unicode__(self):
+ def __str__(self):
return six.text_type(self.num)
class Meta:
diff --git a/tests/modeltests/m2m_intermediary/models.py b/tests/modeltests/m2m_intermediary/models.py
index 85786e8458..e9ae422afb 100644
--- a/tests/modeltests/m2m_intermediary/models.py
+++ b/tests/modeltests/m2m_intermediary/models.py
@@ -12,27 +12,31 @@ field, which specifies the ``Reporter``'s position for the given article
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Reporter(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateField()
- def __unicode__(self):
+ def __str__(self):
return self.headline
+@python_2_unicode_compatible
class Writer(models.Model):
reporter = models.ForeignKey(Reporter)
article = models.ForeignKey(Article)
position = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return '%s (%s)' % (self.reporter, self.position)
diff --git a/tests/modeltests/m2m_multiple/models.py b/tests/modeltests/m2m_multiple/models.py
index 3efe7108b9..c2e3b030a4 100644
--- a/tests/modeltests/m2m_multiple/models.py
+++ b/tests/modeltests/m2m_multiple/models.py
@@ -8,16 +8,19 @@ Set ``related_name`` to designate what the reverse relationship is called.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Category(models.Model):
name = models.CharField(max_length=20)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=50)
pub_date = models.DateTimeField()
@@ -26,6 +29,6 @@ class Article(models.Model):
class Meta:
ordering = ('pub_date',)
- def __unicode__(self):
+ def __str__(self):
return self.headline
diff --git a/tests/modeltests/m2m_recursive/models.py b/tests/modeltests/m2m_recursive/models.py
index 83c943ae60..b69930208c 100644
--- a/tests/modeltests/m2m_recursive/models.py
+++ b/tests/modeltests/m2m_recursive/models.py
@@ -17,12 +17,14 @@ appropriate.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=20)
friends = models.ManyToManyField('self')
idols = models.ManyToManyField('self', symmetrical=False, related_name='stalkers')
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/m2m_signals/models.py b/tests/modeltests/m2m_signals/models.py
index 526c4a782e..e997d87f21 100644
--- a/tests/modeltests/m2m_signals/models.py
+++ b/tests/modeltests/m2m_signals/models.py
@@ -1,15 +1,18 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Part(models.Model):
name = models.CharField(max_length=20)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Car(models.Model):
name = models.CharField(max_length=20)
default_parts = models.ManyToManyField(Part)
@@ -18,12 +21,13 @@ class Car(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
class SportsCar(Car):
price = models.IntegerField()
+@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=20)
fans = models.ManyToManyField('self', related_name='idols', symmetrical=False)
@@ -32,5 +36,5 @@ class Person(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/m2m_through/models.py b/tests/modeltests/m2m_through/models.py
index aa71a049cb..a896f6d9ff 100644
--- a/tests/modeltests/m2m_through/models.py
+++ b/tests/modeltests/m2m_through/models.py
@@ -1,18 +1,21 @@
from datetime import datetime
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
# M2M described on one of the models
+@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=128)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(Person, through='Membership')
@@ -22,9 +25,10 @@ class Group(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Membership(models.Model):
person = models.ForeignKey(Person)
group = models.ForeignKey(Group)
@@ -34,16 +38,17 @@ class Membership(models.Model):
class Meta:
ordering = ('date_joined', 'invite_reason', 'group')
- def __unicode__(self):
+ def __str__(self):
return "%s is a member of %s" % (self.person.name, self.group.name)
+@python_2_unicode_compatible
class CustomMembership(models.Model):
person = models.ForeignKey(Person, db_column="custom_person_column", related_name="custom_person_related_name")
group = models.ForeignKey(Group)
weird_fk = models.ForeignKey(Membership, null=True)
date_joined = models.DateTimeField(default=datetime.now)
- def __unicode__(self):
+ def __str__(self):
return "%s is a member of %s" % (self.person.name, self.group.name)
class Meta:
@@ -54,11 +59,12 @@ class TestNoDefaultsOrNulls(models.Model):
group = models.ForeignKey(Group)
nodefaultnonull = models.CharField(max_length=5)
+@python_2_unicode_compatible
class PersonSelfRefM2M(models.Model):
name = models.CharField(max_length=5)
friends = models.ManyToManyField('self', through="Friendship", symmetrical=False)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Friendship(models.Model):
diff --git a/tests/modeltests/m2o_recursive/models.py b/tests/modeltests/m2o_recursive/models.py
index c0a4bdeec2..2775d713dd 100644
--- a/tests/modeltests/m2o_recursive/models.py
+++ b/tests/modeltests/m2o_recursive/models.py
@@ -11,19 +11,22 @@ Set ``related_name`` to designate what the reverse relationship is called.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Category(models.Model):
name = models.CharField(max_length=20)
parent = models.ForeignKey('self', blank=True, null=True, related_name='child_set')
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Person(models.Model):
full_name = models.CharField(max_length=20)
mother = models.ForeignKey('self', null=True, related_name='mothers_child_set')
father = models.ForeignKey('self', null=True, related_name='fathers_child_set')
- def __unicode__(self):
+ def __str__(self):
return self.full_name
diff --git a/tests/modeltests/many_to_many/models.py b/tests/modeltests/many_to_many/models.py
index 5076e35653..a196c85092 100644
--- a/tests/modeltests/many_to_many/models.py
+++ b/tests/modeltests/many_to_many/models.py
@@ -8,22 +8,25 @@ objects, and a ``Publication`` has multiple ``Article`` objects.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Publication(models.Model):
title = models.CharField(max_length=30)
- def __unicode__(self):
+ def __str__(self):
return self.title
class Meta:
ordering = ('title',)
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Meta:
diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py
index 0d2688e8a4..4e2ed67eea 100644
--- a/tests/modeltests/many_to_one/models.py
+++ b/tests/modeltests/many_to_one/models.py
@@ -6,22 +6,25 @@ To define a many-to-one relationship, use ``ForeignKey()``.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Reporter(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.EmailField()
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateField()
reporter = models.ForeignKey(Reporter)
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Meta:
diff --git a/tests/modeltests/many_to_one_null/models.py b/tests/modeltests/many_to_one_null/models.py
index be7e650c65..e00ca85928 100644
--- a/tests/modeltests/many_to_one_null/models.py
+++ b/tests/modeltests/many_to_one_null/models.py
@@ -6,14 +6,17 @@ To define a many-to-one relationship that can have a null foreign key, use
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Reporter(models.Model):
name = models.CharField(max_length=30)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
reporter = models.ForeignKey(Reporter, null=True)
@@ -21,5 +24,5 @@ class Article(models.Model):
class Meta:
ordering = ('headline',)
- def __unicode__(self):
+ def __str__(self):
return self.headline
diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py
index 8942b21f73..f4bdcad4af 100644
--- a/tests/modeltests/model_forms/models.py
+++ b/tests/modeltests/model_forms/models.py
@@ -14,6 +14,7 @@ import tempfile
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
temp_storage_dir = tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
@@ -31,23 +32,26 @@ ARTICLE_STATUS_CHAR = (
('l', 'Live'),
)
+@python_2_unicode_compatible
class Category(models.Model):
name = models.CharField(max_length=20)
slug = models.SlugField(max_length=20)
url = models.CharField('The URL', max_length=40)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Writer(models.Model):
name = models.CharField(max_length=50, help_text='Use both first and last names.')
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=50)
slug = models.SlugField()
@@ -64,7 +68,7 @@ class Article(models.Model):
self.created = datetime.date.today()
return super(Article, self).save()
- def __unicode__(self):
+ def __str__(self):
return self.headline
class ImprovedArticle(models.Model):
@@ -76,26 +80,29 @@ class ImprovedArticleWithParentLink(models.Model):
class BetterWriter(Writer):
score = models.IntegerField()
+@python_2_unicode_compatible
class WriterProfile(models.Model):
writer = models.OneToOneField(Writer, primary_key=True)
age = models.PositiveIntegerField()
- def __unicode__(self):
+ def __str__(self):
return "%s is %s" % (self.writer, self.age)
from django.contrib.localflavor.us.models import PhoneNumberField
+@python_2_unicode_compatible
class PhoneNumber(models.Model):
phone = PhoneNumberField()
description = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return self.phone
+@python_2_unicode_compatible
class TextFile(models.Model):
description = models.CharField(max_length=20)
file = models.FileField(storage=temp_storage, upload_to='tests', max_length=15)
- def __unicode__(self):
+ def __str__(self):
return self.description
try:
@@ -110,6 +117,7 @@ try:
test_images = True
+ @python_2_unicode_compatible
class ImageFile(models.Model):
def custom_upload_path(self, filename):
path = self.path or 'tests'
@@ -125,9 +133,10 @@ try:
width_field='width', height_field='height')
path = models.CharField(max_length=16, blank=True, default='')
- def __unicode__(self):
+ def __str__(self):
return self.description
+ @python_2_unicode_compatible
class OptionalImageFile(models.Model):
def custom_upload_path(self, filename):
path = self.path or 'tests'
@@ -141,28 +150,31 @@ try:
height = models.IntegerField(editable=False, null=True)
path = models.CharField(max_length=16, blank=True, default='')
- def __unicode__(self):
+ def __str__(self):
return self.description
except ImportError:
test_images = False
+@python_2_unicode_compatible
class CommaSeparatedInteger(models.Model):
field = models.CommaSeparatedIntegerField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return self.field
+@python_2_unicode_compatible
class Product(models.Model):
slug = models.SlugField(unique=True)
- def __unicode__(self):
+ def __str__(self):
return self.slug
+@python_2_unicode_compatible
class Price(models.Model):
price = models.DecimalField(max_digits=10, decimal_places=2)
quantity = models.PositiveIntegerField()
- def __unicode__(self):
+ def __str__(self):
return "%s for %s" % (self.quantity, self.price)
class Meta:
@@ -171,6 +183,7 @@ class Price(models.Model):
class ArticleStatus(models.Model):
status = models.CharField(max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True)
+@python_2_unicode_compatible
class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True)
parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
@@ -179,7 +192,7 @@ class Inventory(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Book(models.Model):
@@ -202,31 +215,34 @@ class BookXtra(models.Model):
class DerivedBook(Book, BookXtra):
pass
+@python_2_unicode_compatible
class ExplicitPK(models.Model):
key = models.CharField(max_length=20, primary_key=True)
desc = models.CharField(max_length=20, blank=True, unique=True)
class Meta:
unique_together = ('key', 'desc')
- def __unicode__(self):
+ def __str__(self):
return self.key
+@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
slug = models.CharField(max_length=50, unique_for_year='posted', blank=True)
subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True)
posted = models.DateField()
- def __unicode__(self):
+ def __str__(self):
return self.name
class DerivedPost(Post):
pass
+@python_2_unicode_compatible
class BigInt(models.Model):
biggie = models.BigIntegerField()
- def __unicode__(self):
+ def __str__(self):
return six.text_type(self.biggie)
class MarkupField(models.CharField):
diff --git a/tests/modeltests/model_formsets/models.py b/tests/modeltests/model_formsets/models.py
index a01a2da0fa..ae152448ab 100644
--- a/tests/modeltests/model_formsets/models.py
+++ b/tests/modeltests/model_formsets/models.py
@@ -4,20 +4,23 @@ import datetime
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
class BetterAuthor(Author):
write_speed = models.IntegerField()
+@python_2_unicode_compatible
class Book(models.Model):
author = models.ForeignKey(Author)
title = models.CharField(max_length=100)
@@ -28,20 +31,22 @@ class Book(models.Model):
)
ordering = ['id']
- def __unicode__(self):
+ def __str__(self):
return self.title
+@python_2_unicode_compatible
class BookWithCustomPK(models.Model):
my_pk = models.DecimalField(max_digits=5, decimal_places=0, primary_key=True)
author = models.ForeignKey(Author)
title = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return '%s: %s' % (self.my_pk, self.title)
class Editor(models.Model):
name = models.CharField(max_length=100)
+@python_2_unicode_compatible
class BookWithOptionalAltEditor(models.Model):
author = models.ForeignKey(Author)
# Optional secondary author
@@ -53,21 +58,23 @@ class BookWithOptionalAltEditor(models.Model):
('author', 'title', 'alt_editor'),
)
- def __unicode__(self):
+ def __str__(self):
return self.title
+@python_2_unicode_compatible
class AlternateBook(Book):
notes = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return '%s - %s' % (self.title, self.notes)
+@python_2_unicode_compatible
class AuthorMeeting(models.Model):
name = models.CharField(max_length=100)
authors = models.ManyToManyField(Author)
created = models.DateField(editable=False)
- def __unicode__(self):
+ def __str__(self):
return self.name
class CustomPrimaryKey(models.Model):
@@ -77,19 +84,21 @@ class CustomPrimaryKey(models.Model):
# models for inheritance tests.
+@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
city = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Owner(models.Model):
auto_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
place = models.ForeignKey(Place)
- def __unicode__(self):
+ def __str__(self):
return "%s at %s" % (self.name, self.place)
class Location(models.Model):
@@ -98,30 +107,34 @@ class Location(models.Model):
lat = models.CharField(max_length=100)
lon = models.CharField(max_length=100)
+@python_2_unicode_compatible
class OwnerProfile(models.Model):
owner = models.OneToOneField(Owner, primary_key=True)
age = models.PositiveIntegerField()
- def __unicode__(self):
+ def __str__(self):
return "%s is %d" % (self.owner.name, self.age)
+@python_2_unicode_compatible
class Restaurant(Place):
serves_pizza = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Product(models.Model):
slug = models.SlugField(unique=True)
- def __unicode__(self):
+ def __str__(self):
return self.slug
+@python_2_unicode_compatible
class Price(models.Model):
price = models.DecimalField(max_digits=10, decimal_places=2)
quantity = models.PositiveIntegerField()
- def __unicode__(self):
+ def __str__(self):
return "%s for %s" % (self.quantity, self.price)
class Meta:
@@ -136,12 +149,14 @@ class ClassyMexicanRestaurant(MexicanRestaurant):
# models for testing unique_together validation when a fk is involved and
# using inlineformset_factory.
+@python_2_unicode_compatible
class Repository(models.Model):
name = models.CharField(max_length=25)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Revision(models.Model):
repository = models.ForeignKey(Repository)
revision = models.CharField(max_length=40)
@@ -149,7 +164,7 @@ class Revision(models.Model):
class Meta:
unique_together = (("repository", "revision"),)
- def __unicode__(self):
+ def __str__(self):
return "%s (%s)" % (self.revision, six.text_type(self.repository))
# models for testing callable defaults (see bug #7975). If you define a model
@@ -167,32 +182,36 @@ class Membership(models.Model):
class Team(models.Model):
name = models.CharField(max_length=100)
+@python_2_unicode_compatible
class Player(models.Model):
team = models.ForeignKey(Team, null=True)
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
# Models for testing custom ModelForm save methods in formsets and inline formsets
+@python_2_unicode_compatible
class Poet(models.Model):
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Poem(models.Model):
poet = models.ForeignKey(Poet)
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
slug = models.CharField(max_length=50, unique_for_year='posted', blank=True)
subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True)
posted = models.DateField()
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/model_inheritance/models.py b/tests/modeltests/model_inheritance/models.py
index 37ca603021..2101f394f7 100644
--- a/tests/modeltests/model_inheritance/models.py
+++ b/tests/modeltests/model_inheritance/models.py
@@ -14,11 +14,13 @@ Both styles are demonstrated here.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
#
# Abstract base classes
#
+@python_2_unicode_compatible
class CommonInfo(models.Model):
name = models.CharField(max_length=50)
age = models.PositiveIntegerField()
@@ -27,7 +29,7 @@ class CommonInfo(models.Model):
abstract = True
ordering = ['name']
- def __unicode__(self):
+ def __str__(self):
return '%s %s' % (self.__class__.__name__, self.name)
class Worker(CommonInfo):
@@ -49,6 +51,7 @@ class StudentWorker(Student, Worker):
class Post(models.Model):
title = models.CharField(max_length=50)
+@python_2_unicode_compatible
class Attachment(models.Model):
post = models.ForeignKey(Post, related_name='attached_%(class)s_set')
content = models.TextField()
@@ -56,7 +59,7 @@ class Attachment(models.Model):
class Meta:
abstract = True
- def __unicode__(self):
+ def __str__(self):
return self.content
class Comment(Attachment):
@@ -69,17 +72,19 @@ class Link(Attachment):
# Multi-table inheritance
#
+@python_2_unicode_compatible
class Chef(models.Model):
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return "%s the chef" % self.name
+@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
- def __unicode__(self):
+ def __str__(self):
return "%s the place" % self.name
class Rating(models.Model):
@@ -89,6 +94,7 @@ class Rating(models.Model):
abstract = True
ordering = ['-rating']
+@python_2_unicode_compatible
class Restaurant(Place, Rating):
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
@@ -97,27 +103,30 @@ class Restaurant(Place, Rating):
class Meta(Rating.Meta):
db_table = 'my_restaurant'
- def __unicode__(self):
+ def __str__(self):
return "%s the restaurant" % self.name
+@python_2_unicode_compatible
class ItalianRestaurant(Restaurant):
serves_gnocchi = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return "%s the italian restaurant" % self.name
+@python_2_unicode_compatible
class Supplier(Place):
customers = models.ManyToManyField(Restaurant, related_name='provider')
- def __unicode__(self):
+ def __str__(self):
return "%s the supplier" % self.name
+@python_2_unicode_compatible
class ParkingLot(Place):
# An explicit link to the parent (we can control the attribute name).
parent = models.OneToOneField(Place, primary_key=True, parent_link=True)
main_site = models.ForeignKey(Place, related_name='lot')
- def __unicode__(self):
+ def __str__(self):
return "%s the parking lot" % self.name
#
@@ -139,10 +148,11 @@ class NamedURL(models.Model):
class Meta:
abstract = True
+@python_2_unicode_compatible
class Copy(NamedURL):
content = models.TextField()
- def __unicode__(self):
+ def __str__(self):
return self.content
class Mixin(object):
diff --git a/tests/modeltests/model_inheritance_same_model_name/models.py b/tests/modeltests/model_inheritance_same_model_name/models.py
index de7541694a..801724df18 100644
--- a/tests/modeltests/model_inheritance_same_model_name/models.py
+++ b/tests/modeltests/model_inheritance_same_model_name/models.py
@@ -11,12 +11,14 @@ from __future__ import absolute_import
from django.db import models
from ..model_inheritance.models import NamedURL
+from django.utils.encoding import python_2_unicode_compatible
#
# Abstract base classes with related models
#
+@python_2_unicode_compatible
class Copy(NamedURL):
content = models.TextField()
- def __unicode__(self):
+ def __str__(self):
return self.content
diff --git a/tests/modeltests/one_to_one/models.py b/tests/modeltests/one_to_one/models.py
index 8c6d56a795..9599496cb7 100644
--- a/tests/modeltests/one_to_one/models.py
+++ b/tests/modeltests/one_to_one/models.py
@@ -8,28 +8,32 @@ In this example, a ``Place`` optionally can be a ``Restaurant``.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
- def __unicode__(self):
+ def __str__(self):
return "%s the place" % self.name
+@python_2_unicode_compatible
class Restaurant(models.Model):
place = models.OneToOneField(Place, primary_key=True)
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return "%s the restaurant" % self.place.name
+@python_2_unicode_compatible
class Waiter(models.Model):
restaurant = models.ForeignKey(Restaurant)
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return "%s the waiter at %s" % (self.name, self.restaurant)
class ManualPrimaryKey(models.Model):
@@ -40,10 +44,11 @@ class RelatedModel(models.Model):
link = models.OneToOneField(ManualPrimaryKey)
name = models.CharField(max_length = 50)
+@python_2_unicode_compatible
class MultiModel(models.Model):
link1 = models.OneToOneField(Place)
link2 = models.OneToOneField(ManualPrimaryKey)
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return "Multimodel %s" % self.name
diff --git a/tests/modeltests/or_lookups/models.py b/tests/modeltests/or_lookups/models.py
index 0037b41afb..f146b2e72d 100644
--- a/tests/modeltests/or_lookups/models.py
+++ b/tests/modeltests/or_lookups/models.py
@@ -10,8 +10,10 @@ clauses using the variable ``django.db.models.Q`` (or any object with an
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=50)
pub_date = models.DateTimeField()
@@ -19,5 +21,5 @@ class Article(models.Model):
class Meta:
ordering = ('pub_date',)
- def __unicode__(self):
+ def __str__(self):
return self.headline
diff --git a/tests/modeltests/order_with_respect_to/models.py b/tests/modeltests/order_with_respect_to/models.py
index a4e20c2fe0..06bb56b141 100644
--- a/tests/modeltests/order_with_respect_to/models.py
+++ b/tests/modeltests/order_with_respect_to/models.py
@@ -4,11 +4,13 @@ Tests for the order_with_respect_to Meta attribute.
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
class Question(models.Model):
text = models.CharField(max_length=200)
+@python_2_unicode_compatible
class Answer(models.Model):
text = models.CharField(max_length=200)
question = models.ForeignKey(Question)
@@ -16,9 +18,10 @@ class Answer(models.Model):
class Meta:
order_with_respect_to = 'question'
- def __unicode__(self):
+ def __str__(self):
return six.text_type(self.text)
+@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=200)
parent = models.ForeignKey("self", related_name="children", null=True)
@@ -26,5 +29,5 @@ class Post(models.Model):
class Meta:
order_with_respect_to = "parent"
- def __unicode__(self):
+ def __str__(self):
return self.title
diff --git a/tests/modeltests/ordering/models.py b/tests/modeltests/ordering/models.py
index bfb4b97107..67126e1bda 100644
--- a/tests/modeltests/ordering/models.py
+++ b/tests/modeltests/ordering/models.py
@@ -14,22 +14,25 @@ undefined -- not random, just undefined.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateTimeField()
class Meta:
ordering = ('-pub_date', 'headline')
- def __unicode__(self):
+ def __str__(self):
return self.headline
+@python_2_unicode_compatible
class ArticlePKOrdering(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateTimeField()
class Meta:
ordering = ('-pk',)
- def __unicode__(self):
+ def __str__(self):
return self.headline
diff --git a/tests/modeltests/pagination/models.py b/tests/modeltests/pagination/models.py
index 48484dd59b..779d3029ba 100644
--- a/tests/modeltests/pagination/models.py
+++ b/tests/modeltests/pagination/models.py
@@ -7,11 +7,13 @@ objects into easily readable pages.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
- def __unicode__(self):
+ def __str__(self):
return self.headline
diff --git a/tests/modeltests/prefetch_related/models.py b/tests/modeltests/prefetch_related/models.py
index 589f78c7d3..85488f0879 100644
--- a/tests/modeltests/prefetch_related/models.py
+++ b/tests/modeltests/prefetch_related/models.py
@@ -1,16 +1,18 @@
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
## Basic tests
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=50, unique=True)
first_book = models.ForeignKey('Book', related_name='first_time_authors')
favorite_authors = models.ManyToManyField(
'self', through='FavoriteAuthors', symmetrical=False, related_name='favors_me')
- def __unicode__(self):
+ def __str__(self):
return self.name
class Meta:
@@ -30,6 +32,7 @@ class FavoriteAuthors(models.Model):
ordering = ['id']
+@python_2_unicode_compatible
class AuthorAddress(models.Model):
author = models.ForeignKey(Author, to_field='name', related_name='addresses')
address = models.TextField()
@@ -37,15 +40,16 @@ class AuthorAddress(models.Model):
class Meta:
ordering = ['id']
- def __unicode__(self):
+ def __str__(self):
return self.address
+@python_2_unicode_compatible
class Book(models.Model):
title = models.CharField(max_length=255)
authors = models.ManyToManyField(Author, related_name='books')
- def __unicode__(self):
+ def __str__(self):
return self.title
class Meta:
@@ -58,11 +62,12 @@ class BookWithYear(Book):
AuthorWithAge, related_name='books_with_year')
+@python_2_unicode_compatible
class Reader(models.Model):
name = models.CharField(max_length=50)
books_read = models.ManyToManyField(Book, related_name='read_by')
- def __unicode__(self):
+ def __str__(self):
return self.name
class Meta:
@@ -86,13 +91,14 @@ class TeacherManager(models.Manager):
return super(TeacherManager, self).get_query_set().prefetch_related('qualifications')
+@python_2_unicode_compatible
class Teacher(models.Model):
name = models.CharField(max_length=50)
qualifications = models.ManyToManyField(Qualification)
objects = TeacherManager()
- def __unicode__(self):
+ def __str__(self):
return "%s (%s)" % (self.name, ", ".join(q.name for q in self.qualifications.all()))
class Meta:
@@ -109,6 +115,7 @@ class Department(models.Model):
## GenericRelation/GenericForeignKey tests
+@python_2_unicode_compatible
class TaggedItem(models.Model):
tag = models.SlugField()
content_type = models.ForeignKey(ContentType, related_name="taggeditem_set2")
@@ -119,7 +126,7 @@ class TaggedItem(models.Model):
created_by_fkey = models.PositiveIntegerField(null=True)
created_by = generic.GenericForeignKey('created_by_ct', 'created_by_fkey',)
- def __unicode__(self):
+ def __str__(self):
return self.tag
@@ -169,12 +176,13 @@ class Person(models.Model):
## Models for nullable FK tests
+@python_2_unicode_compatible
class Employee(models.Model):
name = models.CharField(max_length=50)
boss = models.ForeignKey('self', null=True,
related_name='serfs')
- def __unicode__(self):
+ def __str__(self):
return self.name
class Meta:
diff --git a/tests/modeltests/proxy_models/models.py b/tests/modeltests/proxy_models/models.py
index 49fd87deff..6c962aadc8 100644
--- a/tests/modeltests/proxy_models/models.py
+++ b/tests/modeltests/proxy_models/models.py
@@ -5,6 +5,7 @@ than using a new table of their own. This allows them to act as simple proxies,
providing a modified interface to the data from the base class.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
# A couple of managers for testing managing overriding in proxy model cases.
@@ -16,6 +17,7 @@ class SubManager(models.Manager):
def get_query_set(self):
return super(SubManager, self).get_query_set().exclude(name="wilma")
+@python_2_unicode_compatible
class Person(models.Model):
"""
A simple concrete base class.
@@ -24,7 +26,7 @@ class Person(models.Model):
objects = PersonManager()
- def __unicode__(self):
+ def __str__(self):
return self.name
class Abstract(models.Model):
@@ -82,10 +84,11 @@ class MyPersonProxy(MyPerson):
class LowerStatusPerson(MyPersonProxy):
status = models.CharField(max_length=80)
+@python_2_unicode_compatible
class User(models.Model):
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
class UserProxy(User):
@@ -100,11 +103,12 @@ class UserProxyProxy(UserProxy):
class Country(models.Model):
name = models.CharField(max_length=50)
+@python_2_unicode_compatible
class State(models.Model):
name = models.CharField(max_length=50)
country = models.ForeignKey(Country)
- def __unicode__(self):
+ def __str__(self):
return self.name
class StateProxy(State):
@@ -124,11 +128,12 @@ class ProxyTrackerUser(TrackerUser):
proxy = True
+@python_2_unicode_compatible
class Issue(models.Model):
summary = models.CharField(max_length=255)
assignee = models.ForeignKey(TrackerUser)
- def __unicode__(self):
+ def __str__(self):
return ':'.join((self.__class__.__name__,self.summary,))
class Bug(Issue):
diff --git a/tests/modeltests/reserved_names/models.py b/tests/modeltests/reserved_names/models.py
index 010649e681..8e942b20e8 100644
--- a/tests/modeltests/reserved_names/models.py
+++ b/tests/modeltests/reserved_names/models.py
@@ -8,8 +8,10 @@ reserved-name usage.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Thing(models.Model):
when = models.CharField(max_length=1, primary_key=True)
join = models.CharField(max_length=1)
@@ -22,5 +24,5 @@ class Thing(models.Model):
class Meta:
db_table = 'select'
- def __unicode__(self):
- return self.when \ No newline at end of file
+ def __str__(self):
+ return self.when
diff --git a/tests/modeltests/reverse_lookup/models.py b/tests/modeltests/reverse_lookup/models.py
index bb7a163327..ed58177770 100644
--- a/tests/modeltests/reverse_lookup/models.py
+++ b/tests/modeltests/reverse_lookup/models.py
@@ -5,25 +5,29 @@ This demonstrates the reverse lookup features of the database API.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class User(models.Model):
name = models.CharField(max_length=200)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Poll(models.Model):
question = models.CharField(max_length=200)
creator = models.ForeignKey(User)
- def __unicode__(self):
+ def __str__(self):
return self.question
+@python_2_unicode_compatible
class Choice(models.Model):
name = models.CharField(max_length=100)
poll = models.ForeignKey(Poll, related_name="poll_choice")
related_poll = models.ForeignKey(Poll, related_name="related_choice")
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/save_delete_hooks/models.py b/tests/modeltests/save_delete_hooks/models.py
index bae60e4b86..a6e1abfb77 100644
--- a/tests/modeltests/save_delete_hooks/models.py
+++ b/tests/modeltests/save_delete_hooks/models.py
@@ -7,8 +7,10 @@ the methods.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
@@ -17,7 +19,7 @@ class Person(models.Model):
super(Person, self).__init__(*args, **kwargs)
self.data = []
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
def save(self, *args, **kwargs):
diff --git a/tests/modeltests/select_related/models.py b/tests/modeltests/select_related/models.py
index 3c2e7721fd..ec41957adf 100644
--- a/tests/modeltests/select_related/models.py
+++ b/tests/modeltests/select_related/models.py
@@ -8,52 +8,61 @@ the select-related behavior will traverse.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
# Who remembers high school biology?
+@python_2_unicode_compatible
class Domain(models.Model):
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Kingdom(models.Model):
name = models.CharField(max_length=50)
domain = models.ForeignKey(Domain)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Phylum(models.Model):
name = models.CharField(max_length=50)
kingdom = models.ForeignKey(Kingdom)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Klass(models.Model):
name = models.CharField(max_length=50)
phylum = models.ForeignKey(Phylum)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Order(models.Model):
name = models.CharField(max_length=50)
klass = models.ForeignKey(Klass)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Family(models.Model):
name = models.CharField(max_length=50)
order = models.ForeignKey(Order)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Genus(models.Model):
name = models.CharField(max_length=50)
family = models.ForeignKey(Family)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Species(models.Model):
name = models.CharField(max_length=50)
genus = models.ForeignKey(Genus)
- def __unicode__(self):
- return self.name \ No newline at end of file
+ def __str__(self):
+ return self.name
diff --git a/tests/modeltests/serializers/models.py b/tests/modeltests/serializers/models.py
index ebae7605b4..290478607b 100644
--- a/tests/modeltests/serializers/models.py
+++ b/tests/modeltests/serializers/models.py
@@ -11,28 +11,32 @@ from decimal import Decimal
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Category(models.Model):
name = models.CharField(max_length=20)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=20)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Article(models.Model):
author = models.ForeignKey(Author)
headline = models.CharField(max_length=50)
@@ -42,28 +46,31 @@ class Article(models.Model):
class Meta:
ordering = ('pub_date',)
- def __unicode__(self):
+ def __str__(self):
return self.headline
+@python_2_unicode_compatible
class AuthorProfile(models.Model):
author = models.OneToOneField(Author, primary_key=True)
date_of_birth = models.DateField()
- def __unicode__(self):
+ def __str__(self):
return "Profile of %s" % self.author
+@python_2_unicode_compatible
class Actor(models.Model):
name = models.CharField(max_length=20, primary_key=True)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Movie(models.Model):
actor = models.ForeignKey(Actor)
title = models.CharField(max_length=50)
@@ -72,7 +79,7 @@ class Movie(models.Model):
class Meta:
ordering = ('title',)
- def __unicode__(self):
+ def __str__(self):
return self.title
@@ -80,11 +87,12 @@ class Score(models.Model):
score = models.FloatField()
+@python_2_unicode_compatible
class Team(object):
def __init__(self, title):
self.title = title
- def __unicode__(self):
+ def __str__(self):
raise NotImplementedError("Not so simple")
def to_string(self):
@@ -109,10 +117,11 @@ class TeamField(models.CharField):
return self._get_val_from_obj(obj).to_string()
+@python_2_unicode_compatible
class Player(models.Model):
name = models.CharField(max_length=50)
rank = models.IntegerField()
team = TeamField()
- def __unicode__(self):
+ def __str__(self):
return '%s (%d) playing for %s' % (self.name, self.rank, self.team.to_string())
diff --git a/tests/modeltests/signals/models.py b/tests/modeltests/signals/models.py
index 18ca467655..e54a22fce9 100644
--- a/tests/modeltests/signals/models.py
+++ b/tests/modeltests/signals/models.py
@@ -4,18 +4,21 @@ Testing signals before/after saving and deleting.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+@python_2_unicode_compatible
class Car(models.Model):
make = models.CharField(max_length=20)
model = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.make, self.model)
diff --git a/tests/modeltests/str/models.py b/tests/modeltests/str/models.py
index 6f6b877c88..488012e861 100644
--- a/tests/modeltests/str/models.py
+++ b/tests/modeltests/str/models.py
@@ -15,6 +15,7 @@ if you prefer. You must be careful to encode the results correctly, though.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class Article(models.Model):
@@ -26,9 +27,10 @@ class Article(models.Model):
# in ASCII.
return self.headline
+@python_2_unicode_compatible
class InternationalArticle(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateTimeField()
- def __unicode__(self):
- return self.headline \ No newline at end of file
+ def __str__(self):
+ return self.headline
diff --git a/tests/modeltests/transactions/models.py b/tests/modeltests/transactions/models.py
index 7a51b9ac1c..0f8d6b16ec 100644
--- a/tests/modeltests/transactions/models.py
+++ b/tests/modeltests/transactions/models.py
@@ -9,8 +9,10 @@ manually.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Reporter(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
@@ -19,5 +21,5 @@ class Reporter(models.Model):
class Meta:
ordering = ('first_name', 'last_name')
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
diff --git a/tests/modeltests/unmanaged_models/models.py b/tests/modeltests/unmanaged_models/models.py
index 00303cf17a..0eef69977c 100644
--- a/tests/modeltests/unmanaged_models/models.py
+++ b/tests/modeltests/unmanaged_models/models.py
@@ -4,9 +4,11 @@ is generated for the table on various manage.py operations.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
# All of these models are created in the database by Django.
+@python_2_unicode_compatible
class A01(models.Model):
f_a = models.CharField(max_length=10, db_index=True)
f_b = models.IntegerField()
@@ -14,9 +16,10 @@ class A01(models.Model):
class Meta:
db_table = 'a01'
- def __unicode__(self):
+ def __str__(self):
return self.f_a
+@python_2_unicode_compatible
class B01(models.Model):
fk_a = models.ForeignKey(A01)
f_a = models.CharField(max_length=10, db_index=True)
@@ -27,9 +30,10 @@ class B01(models.Model):
# 'managed' is True by default. This tests we can set it explicitly.
managed = True
- def __unicode__(self):
+ def __str__(self):
return self.f_a
+@python_2_unicode_compatible
class C01(models.Model):
mm_a = models.ManyToManyField(A01, db_table='d01')
f_a = models.CharField(max_length=10, db_index=True)
@@ -38,13 +42,14 @@ class C01(models.Model):
class Meta:
db_table = 'c01'
- def __unicode__(self):
+ def __str__(self):
return self.f_a
# All of these models use the same tables as the previous set (they are shadows
# of possibly a subset of the columns). There should be no creation errors,
# since we have told Django they aren't managed by Django.
+@python_2_unicode_compatible
class A02(models.Model):
f_a = models.CharField(max_length=10, db_index=True)
@@ -52,9 +57,10 @@ class A02(models.Model):
db_table = 'a01'
managed = False
- def __unicode__(self):
+ def __str__(self):
return self.f_a
+@python_2_unicode_compatible
class B02(models.Model):
class Meta:
db_table = 'b01'
@@ -64,11 +70,12 @@ class B02(models.Model):
f_a = models.CharField(max_length=10, db_index=True)
f_b = models.IntegerField()
- def __unicode__(self):
+ def __str__(self):
return self.f_a
# To re-use the many-to-many intermediate table, we need to manually set up
# things up.
+@python_2_unicode_compatible
class C02(models.Model):
mm_a = models.ManyToManyField(A02, through="Intermediate")
f_a = models.CharField(max_length=10, db_index=True)
@@ -78,7 +85,7 @@ class C02(models.Model):
db_table = 'c01'
managed = False
- def __unicode__(self):
+ def __str__(self):
return self.f_a
class Intermediate(models.Model):
diff --git a/tests/modeltests/update/models.py b/tests/modeltests/update/models.py
index b93e4a7aae..08472d98b1 100644
--- a/tests/modeltests/update/models.py
+++ b/tests/modeltests/update/models.py
@@ -5,21 +5,24 @@ updates.
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class DataPoint(models.Model):
name = models.CharField(max_length=20)
value = models.CharField(max_length=20)
another_value = models.CharField(max_length=20, blank=True)
- def __unicode__(self):
+ def __str__(self):
return six.text_type(self.name)
+@python_2_unicode_compatible
class RelatedPoint(models.Model):
name = models.CharField(max_length=20)
data = models.ForeignKey(DataPoint)
- def __unicode__(self):
+ def __str__(self):
return six.text_type(self.name)
diff --git a/tests/modeltests/update_only_fields/models.py b/tests/modeltests/update_only_fields/models.py
index 968dba9916..01184f715b 100644
--- a/tests/modeltests/update_only_fields/models.py
+++ b/tests/modeltests/update_only_fields/models.py
@@ -1,5 +1,6 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
GENDER_CHOICES = (
('M', 'Male'),
@@ -10,11 +11,12 @@ class Account(models.Model):
num = models.IntegerField()
+@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=20)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
- def __unicode__(self):
+ def __str__(self):
return self.name
@@ -24,11 +26,12 @@ class Employee(Person):
accounts = models.ManyToManyField('Account', related_name='employees', blank=True, null=True)
+@python_2_unicode_compatible
class Profile(models.Model):
name = models.CharField(max_length=200)
salary = models.FloatField(default=1000.0)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py
index 26fff4b863..dcd9ced52c 100644
--- a/tests/modeltests/validation/models.py
+++ b/tests/modeltests/validation/models.py
@@ -4,6 +4,7 @@ from datetime import datetime
from django.core.exceptions import ValidationError
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
def validate_answer_to_universe(value):
@@ -66,13 +67,14 @@ class Article(models.Model):
if self.pub_date is None:
self.pub_date = datetime.now()
+@python_2_unicode_compatible
class Post(models.Model):
title = models.CharField(max_length=50, unique_for_date='posted', blank=True)
slug = models.CharField(max_length=50, unique_for_year='posted', blank=True)
subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True)
posted = models.DateField()
- def __unicode__(self):
+ def __str__(self):
return self.name
class FlexibleDatePost(models.Model):
diff --git a/tests/regressiontests/admin_changelist/models.py b/tests/regressiontests/admin_changelist/models.py
index 487db50689..4ba2f9c503 100644
--- a/tests/regressiontests/admin_changelist/models.py
+++ b/tests/regressiontests/admin_changelist/models.py
@@ -1,4 +1,5 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class Event(models.Model):
# Oracle can have problems with a column named "date"
@@ -20,17 +21,19 @@ class Band(models.Model):
nr_of_members = models.PositiveIntegerField()
genres = models.ManyToManyField(Genre)
+@python_2_unicode_compatible
class Musician(models.Model):
name = models.CharField(max_length=30)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Group(models.Model):
name = models.CharField(max_length=30)
members = models.ManyToManyField(Musician, through='Membership')
- def __unicode__(self):
+ def __str__(self):
return self.name
class Membership(models.Model):
diff --git a/tests/regressiontests/admin_custom_urls/models.py b/tests/regressiontests/admin_custom_urls/models.py
index facb4b52e7..4bc9ce561e 100644
--- a/tests/regressiontests/admin_custom_urls/models.py
+++ b/tests/regressiontests/admin_custom_urls/models.py
@@ -2,13 +2,15 @@ from functools import update_wrapper
from django.contrib import admin
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Action(models.Model):
name = models.CharField(max_length=50, primary_key=True)
description = models.CharField(max_length=70)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/regressiontests/admin_filters/models.py b/tests/regressiontests/admin_filters/models.py
index 371c67061f..e0b8bde2de 100644
--- a/tests/regressiontests/admin_filters/models.py
+++ b/tests/regressiontests/admin_filters/models.py
@@ -2,8 +2,10 @@ from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Book(models.Model):
title = models.CharField(max_length=50)
year = models.PositiveIntegerField(null=True, blank=True)
@@ -13,20 +15,22 @@ class Book(models.Model):
date_registered = models.DateField(null=True)
no = models.IntegerField(verbose_name='number', blank=True, null=True) # This field is intentionally 2 characters long. See #16080.
- def __unicode__(self):
+ def __str__(self):
return self.title
+@python_2_unicode_compatible
class Department(models.Model):
code = models.CharField(max_length=4, unique=True)
description = models.CharField(max_length=50, blank=True, null=True)
- def __unicode__(self):
+ def __str__(self):
return self.description
+@python_2_unicode_compatible
class Employee(models.Model):
department = models.ForeignKey(Department, to_field="code")
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/regressiontests/admin_inlines/models.py b/tests/regressiontests/admin_inlines/models.py
index 5a0f4d84b9..5b703a7481 100644
--- a/tests/regressiontests/admin_inlines/models.py
+++ b/tests/regressiontests/admin_inlines/models.py
@@ -7,22 +7,26 @@ from __future__ import unicode_literals
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Parent(models.Model):
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Teacher(models.Model):
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Child(models.Model):
name = models.CharField(max_length=50)
teacher = models.ForeignKey(Teacher)
@@ -31,7 +35,7 @@ class Child(models.Model):
object_id = models.PositiveIntegerField()
parent = generic.GenericForeignKey()
- def __unicode__(self):
+ def __str__(self):
return 'I am %s, a child of %s' % (self.name, self.parent)
diff --git a/tests/regressiontests/admin_scripts/models.py b/tests/regressiontests/admin_scripts/models.py
index da803d0174..cd96052098 100644
--- a/tests/regressiontests/admin_scripts/models.py
+++ b/tests/regressiontests/admin_scripts/models.py
@@ -1,11 +1,13 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Meta:
diff --git a/tests/regressiontests/admin_util/models.py b/tests/regressiontests/admin_util/models.py
index 5541097022..b3504a1fa4 100644
--- a/tests/regressiontests/admin_util/models.py
+++ b/tests/regressiontests/admin_util/models.py
@@ -1,5 +1,6 @@
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
class Article(models.Model):
@@ -18,11 +19,12 @@ class Article(models.Model):
return "nothing"
test_from_model_with_override.short_description = "not What you Expect"
+@python_2_unicode_compatible
class Count(models.Model):
num = models.PositiveSmallIntegerField()
parent = models.ForeignKey('self', null=True)
- def __unicode__(self):
+ def __str__(self):
return six.text_type(self.num)
class Event(models.Model):
diff --git a/tests/regressiontests/admin_validation/models.py b/tests/regressiontests/admin_validation/models.py
index 5e080a9232..d23849a2a8 100644
--- a/tests/regressiontests/admin_validation/models.py
+++ b/tests/regressiontests/admin_validation/models.py
@@ -3,12 +3,14 @@ Tests of ModelAdmin validation logic.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class Album(models.Model):
title = models.CharField(max_length=150)
+@python_2_unicode_compatible
class Song(models.Model):
title = models.CharField(max_length=150)
album = models.ForeignKey(Album)
@@ -17,7 +19,7 @@ class Song(models.Model):
class Meta:
ordering = ('title',)
- def __unicode__(self):
+ def __str__(self):
return self.title
def readonly_method_on_model(self):
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index aee193b572..0d5e327ecf 100644
--- a/tests/regressiontests/admin_views/models.py
+++ b/tests/regressiontests/admin_views/models.py
@@ -10,6 +10,7 @@ from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.core.files.storage import FileSystemStorage
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class Section(models.Model):
@@ -20,6 +21,7 @@ class Section(models.Model):
name = models.CharField(max_length=100)
+@python_2_unicode_compatible
class Article(models.Model):
"""
A simple article to test admin views. Test backwards compatibility.
@@ -29,7 +31,7 @@ class Article(models.Model):
date = models.DateTimeField()
section = models.ForeignKey(Section, null=True, blank=True)
- def __unicode__(self):
+ def __str__(self):
return self.title
def model_year(self):
@@ -38,30 +40,33 @@ class Article(models.Model):
model_year.short_description = ''
+@python_2_unicode_compatible
class Book(models.Model):
"""
A simple book that has chapters.
"""
name = models.CharField(max_length=100, verbose_name='¿Name?')
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Promo(models.Model):
name = models.CharField(max_length=100, verbose_name='¿Name?')
book = models.ForeignKey(Book)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Chapter(models.Model):
title = models.CharField(max_length=100, verbose_name='¿Title?')
content = models.TextField()
book = models.ForeignKey(Book)
- def __unicode__(self):
+ def __str__(self):
return self.title
class Meta:
@@ -69,19 +74,21 @@ class Chapter(models.Model):
verbose_name = '¿Chapter?'
+@python_2_unicode_compatible
class ChapterXtra1(models.Model):
chap = models.OneToOneField(Chapter, verbose_name='¿Chap?')
xtra = models.CharField(max_length=100, verbose_name='¿Xtra?')
- def __unicode__(self):
+ def __str__(self):
return '¿Xtra1: %s' % self.xtra
+@python_2_unicode_compatible
class ChapterXtra2(models.Model):
chap = models.OneToOneField(Chapter, verbose_name='¿Chap?')
xtra = models.CharField(max_length=100, verbose_name='¿Xtra?')
- def __unicode__(self):
+ def __str__(self):
return '¿Xtra2: %s' % self.xtra
@@ -94,20 +101,22 @@ class CustomArticle(models.Model):
date = models.DateTimeField()
+@python_2_unicode_compatible
class ModelWithStringPrimaryKey(models.Model):
string_pk = models.CharField(max_length=255, primary_key=True)
- def __unicode__(self):
+ def __str__(self):
return self.string_pk
def get_absolute_url(self):
return '/dummy/%s/' % self.string_pk
+@python_2_unicode_compatible
class Color(models.Model):
value = models.CharField(max_length=10)
warm = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return self.value
# we replicate Color to register with another ModelAdmin
@@ -115,29 +124,33 @@ class Color2(Color):
class Meta:
proxy = True
+@python_2_unicode_compatible
class Thing(models.Model):
title = models.CharField(max_length=20)
color = models.ForeignKey(Color, limit_choices_to={'warm': True})
- def __unicode__(self):
+ def __str__(self):
return self.title
+@python_2_unicode_compatible
class Actor(models.Model):
name = models.CharField(max_length=50)
age = models.IntegerField()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Inquisition(models.Model):
expected = models.BooleanField()
leader = models.ForeignKey(Actor)
country = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return "by %s from %s" % (self.leader, self.country)
+@python_2_unicode_compatible
class Sketch(models.Model):
title = models.CharField(max_length=100)
inquisition = models.ForeignKey(Inquisition, limit_choices_to={'leader__name': 'Palin',
@@ -145,7 +158,7 @@ class Sketch(models.Model):
'expected': False,
})
- def __unicode__(self):
+ def __str__(self):
return self.title
@@ -161,6 +174,7 @@ class Fabric(models.Model):
surface = models.CharField(max_length=20, choices=NG_CHOICES)
+@python_2_unicode_compatible
class Person(models.Model):
GENDER_CHOICES = (
(1, "Male"),
@@ -171,20 +185,22 @@ class Person(models.Model):
age = models.IntegerField(default=21)
alive = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Persona(models.Model):
"""
A simple persona associated with accounts, to test inlining of related
accounts which inherit from a common accounts class.
"""
name = models.CharField(blank=False, max_length=80)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Account(models.Model):
"""
A simple, generic account encapsulating the information shared by all
@@ -194,7 +210,7 @@ class Account(models.Model):
persona = models.ForeignKey(Persona, related_name="accounts")
servicename = 'generic service'
- def __unicode__(self):
+ def __str__(self):
return "%s: %s" % (self.servicename, self.username)
@@ -208,11 +224,12 @@ class BarAccount(Account):
servicename = 'bar'
+@python_2_unicode_compatible
class Subscriber(models.Model):
name = models.CharField(blank=False, max_length=80)
email = models.EmailField(blank=False, max_length=175)
- def __unicode__(self):
+ def __str__(self):
return "%s (%s)" % (self.name, self.email)
@@ -249,8 +266,9 @@ class Child(models.Model):
name = models.CharField(max_length=30, blank=True)
+@python_2_unicode_compatible
class EmptyModel(models.Model):
- def __unicode__(self):
+ def __str__(self):
return "Primary key = %s" % self.id
@@ -332,6 +350,7 @@ class FancyDoodad(Doodad):
expensive = models.BooleanField(default=True)
+@python_2_unicode_compatible
class Category(models.Model):
collector = models.ForeignKey(Collector)
order = models.PositiveIntegerField()
@@ -339,7 +358,7 @@ class Category(models.Model):
class Meta:
ordering = ('order',)
- def __unicode__(self):
+ def __str__(self):
return '%s:o%s' % (self.id, self.order)
@@ -376,17 +395,19 @@ class Post(models.Model):
return "Very awesome."
+@python_2_unicode_compatible
class Gadget(models.Model):
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Villain(models.Model):
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
@@ -394,6 +415,7 @@ class SuperVillain(Villain):
pass
+@python_2_unicode_compatible
class FunkyTag(models.Model):
"Because we all know there's only one real use case for GFKs."
name = models.CharField(max_length=25)
@@ -401,59 +423,65 @@ class FunkyTag(models.Model):
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Plot(models.Model):
name = models.CharField(max_length=100)
team_leader = models.ForeignKey(Villain, related_name='lead_plots')
contact = models.ForeignKey(Villain, related_name='contact_plots')
tags = generic.GenericRelation(FunkyTag)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class PlotDetails(models.Model):
details = models.CharField(max_length=100)
plot = models.OneToOneField(Plot)
- def __unicode__(self):
+ def __str__(self):
return self.details
+@python_2_unicode_compatible
class SecretHideout(models.Model):
""" Secret! Not registered with the admin! """
location = models.CharField(max_length=100)
villain = models.ForeignKey(Villain)
- def __unicode__(self):
+ def __str__(self):
return self.location
+@python_2_unicode_compatible
class SuperSecretHideout(models.Model):
""" Secret! Not registered with the admin! """
location = models.CharField(max_length=100)
supervillain = models.ForeignKey(SuperVillain)
- def __unicode__(self):
+ def __str__(self):
return self.location
+@python_2_unicode_compatible
class CyclicOne(models.Model):
name = models.CharField(max_length=25)
two = models.ForeignKey('CyclicTwo')
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class CyclicTwo(models.Model):
name = models.CharField(max_length=25)
one = models.ForeignKey(CyclicOne)
- def __unicode__(self):
+ def __str__(self):
return self.name
@@ -484,11 +512,12 @@ class Question(models.Model):
question = models.CharField(max_length=20)
+@python_2_unicode_compatible
class Answer(models.Model):
question = models.ForeignKey(Question, on_delete=models.PROTECT)
answer = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return self.answer
@@ -523,11 +552,12 @@ class Paper(models.Model):
author = models.CharField(max_length=30, blank=True, null=True)
+@python_2_unicode_compatible
class CoverLetter(models.Model):
author = models.CharField(max_length=30)
date_written = models.DateField(null=True, blank=True)
- def __unicode__(self):
+ def __str__(self):
return self.author
@@ -575,10 +605,11 @@ class AdminOrderedCallable(models.Model):
order = models.IntegerField()
stuff = models.CharField(max_length=200)
+@python_2_unicode_compatible
class Report(models.Model):
title = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.title
diff --git a/tests/regressiontests/admin_widgets/models.py b/tests/regressiontests/admin_widgets/models.py
index 81a4ec7aba..2e452798b7 100644
--- a/tests/regressiontests/admin_widgets/models.py
+++ b/tests/regressiontests/admin_widgets/models.py
@@ -2,39 +2,44 @@ from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
+from django.utils.encoding import python_2_unicode_compatible
class MyFileField(models.FileField):
pass
+@python_2_unicode_compatible
class Member(models.Model):
name = models.CharField(max_length=100)
birthdate = models.DateTimeField(blank=True, null=True)
gender = models.CharField(max_length=1, blank=True, choices=[('M','Male'), ('F', 'Female')])
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Band(models.Model):
name = models.CharField(max_length=100)
members = models.ManyToManyField(Member)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Album(models.Model):
band = models.ForeignKey(Band)
name = models.CharField(max_length=100)
cover_art = models.FileField(upload_to='albums')
backside_art = MyFileField(upload_to='albums_back', null=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
class HiddenInventoryManager(models.Manager):
def get_query_set(self):
return super(HiddenInventoryManager, self).get_query_set().filter(hidden=False)
+@python_2_unicode_compatible
class Inventory(models.Model):
barcode = models.PositiveIntegerField(unique=True)
parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
@@ -45,7 +50,7 @@ class Inventory(models.Model):
default_manager = models.Manager()
objects = HiddenInventoryManager()
- def __unicode__(self):
+ def __str__(self):
return self.name
class Event(models.Model):
@@ -56,12 +61,13 @@ class Event(models.Model):
link = models.URLField(blank=True)
min_age = models.IntegerField(blank=True, null=True)
+@python_2_unicode_compatible
class Car(models.Model):
owner = models.ForeignKey(User)
make = models.CharField(max_length=30)
model = models.CharField(max_length=30)
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.make, self.model)
class CarTire(models.Model):
@@ -103,19 +109,21 @@ class Advisor(models.Model):
companies = models.ManyToManyField(Company)
+@python_2_unicode_compatible
class Student(models.Model):
name = models.CharField(max_length=255)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Meta:
ordering = ('name',)
+@python_2_unicode_compatible
class School(models.Model):
name = models.CharField(max_length=255)
students = models.ManyToManyField(Student, related_name='current_schools')
alumni = models.ManyToManyField(Student, related_name='previous_schools')
- def __unicode__(self):
- return self.name \ No newline at end of file
+ def __str__(self):
+ return self.name
diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py
index ccef9a5fc8..dd4ff50aec 100644
--- a/tests/regressiontests/aggregation_regress/models.py
+++ b/tests/regressiontests/aggregation_regress/models.py
@@ -1,24 +1,28 @@
# coding: utf-8
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()
friends = models.ManyToManyField('self', blank=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Publisher(models.Model):
name = models.CharField(max_length=255)
num_awards = models.IntegerField()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Book(models.Model):
isbn = models.CharField(max_length=9)
name = models.CharField(max_length=255)
@@ -33,17 +37,18 @@ class Book(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Store(models.Model):
name = models.CharField(max_length=255)
books = models.ManyToManyField(Book)
original_opening = models.DateTimeField()
friday_night_closing = models.TimeField()
- def __unicode__(self):
+ def __str__(self):
return self.name
class Entries(models.Model):
@@ -58,8 +63,9 @@ class Clues(models.Model):
Clue = models.CharField(max_length=150)
+@python_2_unicode_compatible
class HardbackBook(Book):
weight = models.FloatField()
- def __unicode__(self):
+ def __str__(self):
return "%s (hardback): %s" % (self.name, self.weight)
diff --git a/tests/regressiontests/backends/models.py b/tests/regressiontests/backends/models.py
index af4952dce8..344cf4c798 100644
--- a/tests/regressiontests/backends/models.py
+++ b/tests/regressiontests/backends/models.py
@@ -3,21 +3,24 @@ from __future__ import unicode_literals
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models, connection
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Square(models.Model):
root = models.IntegerField()
square = models.PositiveIntegerField()
- def __unicode__(self):
+ def __str__(self):
return "%s ** 2 == %s" % (self.root, self.square)
+@python_2_unicode_compatible
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
@@ -55,18 +58,20 @@ class Post(models.Model):
db_table = 'CaseSensitive_Post'
+@python_2_unicode_compatible
class Reporter(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateField()
reporter = models.ForeignKey(Reporter)
- def __unicode__(self):
+ def __str__(self):
return self.headline
diff --git a/tests/regressiontests/comment_tests/models.py b/tests/regressiontests/comment_tests/models.py
index 7e16e48419..472b66decd 100644
--- a/tests/regressiontests/comment_tests/models.py
+++ b/tests/regressiontests/comment_tests/models.py
@@ -6,29 +6,33 @@ more information.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
- def __unicode__(self):
+ def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
+@python_2_unicode_compatible
class Article(models.Model):
author = models.ForeignKey(Author)
headline = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.headline
+@python_2_unicode_compatible
class Entry(models.Model):
title = models.CharField(max_length=250)
body = models.TextField()
pub_date = models.DateField()
enable_comments = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return self.title
class Book(models.Model):
diff --git a/tests/regressiontests/custom_columns_regress/models.py b/tests/regressiontests/custom_columns_regress/models.py
index c768c12772..169b2246c3 100644
--- a/tests/regressiontests/custom_columns_regress/models.py
+++ b/tests/regressiontests/custom_columns_regress/models.py
@@ -8,26 +8,29 @@ table creation or queries.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
Article_ID = models.AutoField(primary_key=True, db_column='Article ID')
headline = models.CharField(max_length=100)
authors = models.ManyToManyField('Author', db_table='my m2m table')
primary_author = models.ForeignKey('Author', db_column='Author ID', related_name='primary_set')
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Meta:
ordering = ('headline',)
+@python_2_unicode_compatible
class Author(models.Model):
Author_ID = models.AutoField(primary_key=True, db_column='Author ID')
first_name = models.CharField(max_length=30, db_column='first name')
last_name = models.CharField(max_length=30, db_column='last name')
- def __unicode__(self):
+ def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class Meta:
diff --git a/tests/regressiontests/custom_managers_regress/models.py b/tests/regressiontests/custom_managers_regress/models.py
index 3c4e621769..71073f0fe7 100644
--- a/tests/regressiontests/custom_managers_regress/models.py
+++ b/tests/regressiontests/custom_managers_regress/models.py
@@ -3,6 +3,7 @@ Regression tests for custom manager classes.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class RestrictedManager(models.Manager):
@@ -12,12 +13,14 @@ class RestrictedManager(models.Manager):
def get_query_set(self):
return super(RestrictedManager, self).get_query_set().filter(is_public=True)
+@python_2_unicode_compatible
class RelatedModel(models.Model):
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class RestrictedModel(models.Model):
name = models.CharField(max_length=50)
is_public = models.BooleanField(default=False)
@@ -26,9 +29,10 @@ class RestrictedModel(models.Model):
objects = RestrictedManager()
plain_manager = models.Manager()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class OneToOneRestrictedModel(models.Model):
name = models.CharField(max_length=50)
is_public = models.BooleanField(default=False)
@@ -37,5 +41,5 @@ class OneToOneRestrictedModel(models.Model):
objects = RestrictedManager()
plain_manager = models.Manager()
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/regressiontests/datatypes/models.py b/tests/regressiontests/datatypes/models.py
index d220d0893a..8e6027dd0f 100644
--- a/tests/regressiontests/datatypes/models.py
+++ b/tests/regressiontests/datatypes/models.py
@@ -4,8 +4,10 @@ types, which in the past were problematic for some database backends.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Donut(models.Model):
name = models.CharField(max_length=100)
is_frosted = models.BooleanField(default=False)
@@ -18,7 +20,7 @@ class Donut(models.Model):
class Meta:
ordering = ('consumed_at',)
- def __unicode__(self):
+ def __str__(self):
return self.name
class RumBaba(models.Model):
diff --git a/tests/regressiontests/dates/models.py b/tests/regressiontests/dates/models.py
index e1fc1e74fe..e4bffb7199 100644
--- a/tests/regressiontests/dates/models.py
+++ b/tests/regressiontests/dates/models.py
@@ -1,22 +1,25 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Article(models.Model):
title = models.CharField(max_length=100)
pub_date = models.DateField()
categories = models.ManyToManyField("Category", related_name="articles")
- def __unicode__(self):
+ def __str__(self):
return self.title
+@python_2_unicode_compatible
class Comment(models.Model):
article = models.ForeignKey(Article, related_name="comments")
text = models.TextField()
pub_date = models.DateField()
approval_date = models.DateField(null=True)
- def __unicode__(self):
+ def __str__(self):
return 'Comment to %s (%s)' % (self.article.title, self.pub_date)
class Category(models.Model):
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
index 2852572d32..bdf3c867c6 100644
--- a/tests/regressiontests/defaultfilters/tests.py
+++ b/tests/regressiontests/defaultfilters/tests.py
@@ -9,6 +9,7 @@ from django.test import TestCase
from django.utils import six
from django.utils import unittest, translation
from django.utils.safestring import SafeData
+from django.utils.encoding import python_2_unicode_compatible
class DefaultFiltersTests(TestCase):
@@ -456,10 +457,11 @@ class DefaultFiltersTests(TestCase):
'Lawrence</li>\n\t\t\t<li>Topeka</li>\n\t\t</ul>\n\t\t</li>'\
'\n\t\t<li>Illinois</li>\n\t</ul>\n\t</li>')
+ @python_2_unicode_compatible
class ULItem(object):
def __init__(self, title):
self.title = title
- def __unicode__(self):
+ def __str__(self):
return 'ulitem-%s' % str(self.title)
a = ULItem('a')
diff --git a/tests/regressiontests/defer_regress/models.py b/tests/regressiontests/defer_regress/models.py
index bd4f845f27..d02adccde9 100644
--- a/tests/regressiontests/defer_regress/models.py
+++ b/tests/regressiontests/defer_regress/models.py
@@ -3,15 +3,17 @@ Regression tests for defer() / only() behavior.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Item(models.Model):
name = models.CharField(max_length=15)
text = models.TextField(default="xyzzy")
value = models.IntegerField()
other_value = models.IntegerField(default=0)
- def __unicode__(self):
+ def __str__(self):
return self.name
class RelatedItem(models.Model):
@@ -21,13 +23,14 @@ class Child(models.Model):
name = models.CharField(max_length=10)
value = models.IntegerField()
+@python_2_unicode_compatible
class Leaf(models.Model):
name = models.CharField(max_length=10)
child = models.ForeignKey(Child)
second_child = models.ForeignKey(Child, related_name="other", null=True)
value = models.IntegerField(default=42)
- def __unicode__(self):
+ def __str__(self):
return self.name
class ResolveThis(models.Model):
@@ -38,11 +41,12 @@ class Proxy(Item):
class Meta:
proxy = True
+@python_2_unicode_compatible
class SimpleItem(models.Model):
name = models.CharField(max_length=15)
value = models.IntegerField()
- def __unicode__(self):
+ def __str__(self):
return self.name
class Feature(models.Model):
diff --git a/tests/regressiontests/expressions_regress/models.py b/tests/regressiontests/expressions_regress/models.py
index f3b6999377..711329031d 100644
--- a/tests/regressiontests/expressions_regress/models.py
+++ b/tests/regressiontests/expressions_regress/models.py
@@ -1,15 +1,17 @@
from __future__ import unicode_literals
+from django.utils.encoding import python_2_unicode_compatible
"""
Model for testing arithmetic expressions.
"""
from django.db import models
+@python_2_unicode_compatible
class Number(models.Model):
integer = models.IntegerField(db_column='the_integer')
float = models.FloatField(null=True, db_column='the_float')
- def __unicode__(self):
+ def __str__(self):
return '%i, %.3f' % (self.integer, self.float)
class Experiment(models.Model):
diff --git a/tests/regressiontests/extra_regress/models.py b/tests/regressiontests/extra_regress/models.py
index 7d2a6fab34..11996438b4 100644
--- a/tests/regressiontests/extra_regress/models.py
+++ b/tests/regressiontests/extra_regress/models.py
@@ -5,14 +5,16 @@ import datetime
from django.contrib.auth.models import User
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class RevisionableModel(models.Model):
base = models.ForeignKey('self', null=True)
title = models.CharField(blank=True, max_length=255)
when = models.DateTimeField(default=datetime.datetime.now)
- def __unicode__(self):
+ def __str__(self):
return "%s (%s, %s)" % (self.title, self.id, self.base.id)
def save(self, *args, **kwargs):
@@ -32,11 +34,12 @@ class Order(models.Model):
created_by = models.ForeignKey(User)
text = models.TextField()
+@python_2_unicode_compatible
class TestObject(models.Model):
first = models.CharField(max_length=20)
second = models.CharField(max_length=20)
third = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return 'TestObject: %s,%s,%s' % (self.first,self.second,self.third)
diff --git a/tests/regressiontests/fixtures_regress/models.py b/tests/regressiontests/fixtures_regress/models.py
index 7151cb0ed9..1cc30d2e51 100644
--- a/tests/regressiontests/fixtures_regress/models.py
+++ b/tests/regressiontests/fixtures_regress/models.py
@@ -3,8 +3,10 @@ from __future__ import absolute_import, unicode_literals
from django.contrib.auth.models import User
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Animal(models.Model):
name = models.CharField(max_length=150)
latin_name = models.CharField(max_length=150)
@@ -14,7 +16,7 @@ class Animal(models.Model):
# use a non-default name for the default manager
specimens = models.Manager()
- def __unicode__(self):
+ def __str__(self):
return self.name
@@ -25,11 +27,12 @@ class Plant(models.Model):
# For testing when upper case letter in app name; regression for #4057
db_table = "Fixtures_regress_plant"
+@python_2_unicode_compatible
class Stuff(models.Model):
name = models.CharField(max_length=20, null=True)
owner = models.ForeignKey(User, null=True)
- def __unicode__(self):
+ def __str__(self):
return six.text_type(self.name) + ' is owned by ' + six.text_type(self.owner)
@@ -68,13 +71,14 @@ class Article(models.Model):
# Models to regression test #11428
+@python_2_unicode_compatible
class Widget(models.Model):
name = models.CharField(max_length=255)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
@@ -89,6 +93,7 @@ class TestManager(models.Manager):
return self.get(name=key)
+@python_2_unicode_compatible
class Store(models.Model):
objects = TestManager()
name = models.CharField(max_length=255)
@@ -97,13 +102,14 @@ class Store(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
def natural_key(self):
return (self.name,)
+@python_2_unicode_compatible
class Person(models.Model):
objects = TestManager()
name = models.CharField(max_length=255)
@@ -111,7 +117,7 @@ class Person(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
# Person doesn't actually have a dependency on store, but we need to define
@@ -121,6 +127,7 @@ class Person(models.Model):
natural_key.dependencies = ['fixtures_regress.store']
+@python_2_unicode_compatible
class Book(models.Model):
name = models.CharField(max_length=255)
author = models.ForeignKey(Person)
@@ -129,7 +136,7 @@ class Book(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return '%s by %s (available at %s)' % (
self.name,
self.author.name,
@@ -142,6 +149,7 @@ class NKManager(models.Manager):
return self.get(data=data)
+@python_2_unicode_compatible
class NKChild(Parent):
data = models.CharField(max_length=10, unique=True)
objects = NKManager()
@@ -149,16 +157,17 @@ class NKChild(Parent):
def natural_key(self):
return self.data
- def __unicode__(self):
+ def __str__(self):
return 'NKChild %s:%s' % (self.name, self.data)
+@python_2_unicode_compatible
class RefToNKChild(models.Model):
text = models.CharField(max_length=10)
nk_fk = models.ForeignKey(NKChild, related_name='ref_fks')
nk_m2m = models.ManyToManyField(NKChild, related_name='ref_m2ms')
- def __unicode__(self):
+ def __str__(self):
return '%s: Reference to %s [%s]' % (
self.text,
self.nk_fk,
diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py
index 18e6ddce6d..2f3ee9fa31 100644
--- a/tests/regressiontests/forms/models.py
+++ b/tests/regressiontests/forms/models.py
@@ -7,6 +7,7 @@ import tempfile
from django.core.files.storage import FileSystemStorage
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
temp_storage_location = tempfile.mkdtemp(dir=os.environ['DJANGO_TEST_TEMP_DIR'])
@@ -36,6 +37,7 @@ class ChoiceModel(models.Model):
name = models.CharField(max_length=10)
+@python_2_unicode_compatible
class ChoiceOptionModel(models.Model):
"""Destination for ChoiceFieldModel's ForeignKey.
Can't reuse ChoiceModel because error_message tests require that it have no instances."""
@@ -44,7 +46,7 @@ class ChoiceOptionModel(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return 'ChoiceOption %d' % self.pk
@@ -66,10 +68,11 @@ class FileModel(models.Model):
file = models.FileField(storage=temp_storage, upload_to='tests')
+@python_2_unicode_compatible
class Group(models.Model):
name = models.CharField(max_length=10)
- def __unicode__(self):
+ def __str__(self):
return '%s' % self.name
diff --git a/tests/regressiontests/forms/tests/error_messages.py b/tests/regressiontests/forms/tests/error_messages.py
index f69b419483..b76e122bc0 100644
--- a/tests/regressiontests/forms/tests/error_messages.py
+++ b/tests/regressiontests/forms/tests/error_messages.py
@@ -5,6 +5,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import *
from django.test import TestCase
from django.utils.safestring import mark_safe
+from django.utils.encoding import python_2_unicode_compatible
class AssertFormErrorsMixin(object):
@@ -213,8 +214,9 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
def clean(self):
raise ValidationError("I like to be awkward.")
+ @python_2_unicode_compatible
class CustomErrorList(util.ErrorList):
- def __unicode__(self):
+ def __str__(self):
return self.as_divs()
def as_divs(self):
diff --git a/tests/regressiontests/forms/tests/extra.py b/tests/regressiontests/forms/tests/extra.py
index e0e62858d0..2ab5d40942 100644
--- a/tests/regressiontests/forms/tests/extra.py
+++ b/tests/regressiontests/forms/tests/extra.py
@@ -8,8 +8,9 @@ from django.forms import *
from django.forms.extras import SelectDateWidget
from django.forms.util import ErrorList
from django.test import TestCase
+from django.utils import six
from django.utils import translation
-from django.utils.encoding import force_text, smart_text
+from django.utils.encoding import force_text, smart_text, python_2_unicode_compatible
from .error_messages import AssertFormErrorsMixin
@@ -553,14 +554,24 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
def test_smart_text(self):
class Test:
- def __str__(self):
- return 'ŠĐĆŽćžšđ'.encode('utf-8')
+ if six.PY3:
+ def __str__(self):
+ return 'ŠĐĆŽćžšđ'
+ else:
+ def __str__(self):
+ return 'ŠĐĆŽćžšđ'.encode('utf-8')
class TestU:
- def __str__(self):
- return 'Foo'
- def __unicode__(self):
- return '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
+ if six.PY3:
+ def __str__(self):
+ return 'ŠĐĆŽćžšđ'
+ def __bytes__(self):
+ return b'Foo'
+ else:
+ def __str__(self):
+ return b'Foo'
+ def __unicode__(self):
+ return '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111'
self.assertEqual(smart_text(Test()), '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
self.assertEqual(smart_text(TestU()), '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
@@ -585,8 +596,9 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
self.assertEqual(f.cleaned_data['username'], 'sirrobin')
def test_overriding_errorlist(self):
+ @python_2_unicode_compatible
class DivErrorList(ErrorList):
- def __unicode__(self):
+ def __str__(self):
return self.as_divs()
def as_divs(self):
diff --git a/tests/regressiontests/forms/tests/util.py b/tests/regressiontests/forms/tests/util.py
index b7cc4ec809..c2d213ae23 100644
--- a/tests/regressiontests/forms/tests/util.py
+++ b/tests/regressiontests/forms/tests/util.py
@@ -7,6 +7,7 @@ from django.test import TestCase
from django.utils.safestring import mark_safe
from django.utils import six
from django.utils.translation import ugettext_lazy
+from django.utils.encoding import python_2_unicode_compatible
class FormsUtilTestCase(TestCase):
@@ -46,8 +47,9 @@ class FormsUtilTestCase(TestCase):
self.assertHTMLEqual(str(ErrorList(ValidationError(["First error.", "Not \u03C0.", ugettext_lazy("Error.")]).messages)),
'<ul class="errorlist"><li>First error.</li><li>Not π.</li><li>Error.</li></ul>')
+ @python_2_unicode_compatible
class VeryBadError:
- def __unicode__(self): return "A very bad error."
+ def __str__(self): return "A very bad error."
# Can take a non-string.
self.assertHTMLEqual(str(ErrorList(ValidationError(VeryBadError()).messages)),
diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py
index 3ea42cf549..c950aef719 100644
--- a/tests/regressiontests/forms/tests/widgets.py
+++ b/tests/regressiontests/forms/tests/widgets.py
@@ -13,6 +13,7 @@ from django.utils.safestring import mark_safe
from django.utils import six
from django.utils.translation import activate, deactivate
from django.test import TestCase
+from django.utils.encoding import python_2_unicode_compatible
class FormsWidgetTestCase(TestCase):
@@ -1096,6 +1097,7 @@ class WidgetTests(TestCase):
self.assertFalse(form.is_valid())
+@python_2_unicode_compatible
class FakeFieldFile(object):
"""
Quacks like a FieldFile (has a .url and unicode representation), but
@@ -1104,7 +1106,7 @@ class FakeFieldFile(object):
"""
url = 'something'
- def __unicode__(self):
+ def __str__(self):
return self.url
class ClearableFileInputTests(TestCase):
@@ -1125,10 +1127,11 @@ class ClearableFileInputTests(TestCase):
rendering HTML. Refs #15182.
"""
+ @python_2_unicode_compatible
class StrangeFieldFile(object):
url = "something?chapter=1&sect=2&copy=3&lang=en"
- def __unicode__(self):
+ def __str__(self):
return '''something<div onclick="alert('oops')">.jpg'''
widget = ClearableFileInput()
diff --git a/tests/regressiontests/generic_inline_admin/models.py b/tests/regressiontests/generic_inline_admin/models.py
index a1555666b3..dedc351075 100644
--- a/tests/regressiontests/generic_inline_admin/models.py
+++ b/tests/regressiontests/generic_inline_admin/models.py
@@ -1,6 +1,7 @@
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class Episode(models.Model):
@@ -9,6 +10,7 @@ class Episode(models.Model):
author = models.CharField(max_length=100, blank=True)
+@python_2_unicode_compatible
class Media(models.Model):
"""
Media that can associated to any object.
@@ -20,7 +22,7 @@ class Media(models.Model):
description = models.CharField(max_length=100, blank=True)
keywords = models.CharField(max_length=100, blank=True)
- def __unicode__(self):
+ def __str__(self):
return self.url
#
diff --git a/tests/regressiontests/generic_relations_regress/models.py b/tests/regressiontests/generic_relations_regress/models.py
index 7ec752b02b..dacc9b380b 100644
--- a/tests/regressiontests/generic_relations_regress/models.py
+++ b/tests/regressiontests/generic_relations_regress/models.py
@@ -1,31 +1,36 @@
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
__all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address',
'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2',
'Contact', 'Organization', 'Note')
+@python_2_unicode_compatible
class Link(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
- def __unicode__(self):
+ def __str__(self):
return "Link to %s id=%s" % (self.content_type, self.object_id)
+@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=100)
links = generic.GenericRelation(Link)
- def __unicode__(self):
+ def __str__(self):
return "Place: %s" % self.name
+@python_2_unicode_compatible
class Restaurant(Place):
- def __unicode__(self):
+ def __str__(self):
return "Restaurant: %s" % self.name
+@python_2_unicode_compatible
class Address(models.Model):
street = models.CharField(max_length=80)
city = models.CharField(max_length=50)
@@ -35,15 +40,16 @@ class Address(models.Model):
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
- def __unicode__(self):
+ def __str__(self):
return '%s %s, %s %s' % (self.street, self.city, self.state, self.zipcode)
+@python_2_unicode_compatible
class Person(models.Model):
account = models.IntegerField(primary_key=True)
name = models.CharField(max_length=128)
addresses = generic.GenericRelation(Address)
- def __unicode__(self):
+ def __str__(self):
return self.name
class CharLink(models.Model):
diff --git a/tests/regressiontests/generic_views/models.py b/tests/regressiontests/generic_views/models.py
index 2355769d58..f59389ef78 100644
--- a/tests/regressiontests/generic_views/models.py
+++ b/tests/regressiontests/generic_views/models.py
@@ -1,6 +1,8 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Artist(models.Model):
name = models.CharField(max_length=100)
@@ -9,13 +11,14 @@ class Artist(models.Model):
verbose_name = 'professional artist'
verbose_name_plural = 'professional artists'
- def __unicode__(self):
+ def __str__(self):
return self.name
@models.permalink
def get_absolute_url(self):
return ('artist_detail', (), {'pk': self.id})
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100)
slug = models.SlugField()
@@ -23,9 +26,10 @@ class Author(models.Model):
class Meta:
ordering = ['name']
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Book(models.Model):
name = models.CharField(max_length=300)
slug = models.SlugField()
@@ -36,7 +40,7 @@ class Book(models.Model):
class Meta:
ordering = ['-pubdate']
- def __unicode__(self):
+ def __str__(self):
return self.name
class Page(models.Model):
diff --git a/tests/regressiontests/inline_formsets/models.py b/tests/regressiontests/inline_formsets/models.py
index d76eea758b..40c85fe739 100644
--- a/tests/regressiontests/inline_formsets/models.py
+++ b/tests/regressiontests/inline_formsets/models.py
@@ -1,5 +1,6 @@
# coding: utf-8
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class School(models.Model):
@@ -14,15 +15,17 @@ class Child(models.Model):
school = models.ForeignKey(School)
name = models.CharField(max_length=100)
+@python_2_unicode_compatible
class Poet(models.Model):
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Poem(models.Model):
poet = models.ForeignKey(Poet)
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/regressiontests/introspection/models.py b/tests/regressiontests/introspection/models.py
index 3ca80c5aab..6e5beba61d 100644
--- a/tests/regressiontests/introspection/models.py
+++ b/tests/regressiontests/introspection/models.py
@@ -1,8 +1,10 @@
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Reporter(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
@@ -12,15 +14,16 @@ class Reporter(models.Model):
class Meta:
unique_together = ('first_name', 'last_name')
- def __unicode__(self):
+ def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateField()
reporter = models.ForeignKey(Reporter)
- def __unicode__(self):
+ def __str__(self):
return self.headline
class Meta:
diff --git a/tests/regressiontests/m2m_regress/models.py b/tests/regressiontests/m2m_regress/models.py
index be8dcae9c1..7c1108456e 100644
--- a/tests/regressiontests/m2m_regress/models.py
+++ b/tests/regressiontests/m2m_regress/models.py
@@ -1,37 +1,42 @@
from django.contrib.auth import models as auth
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
# No related name is needed here, since symmetrical relations are not
# explicitly reversible.
+@python_2_unicode_compatible
class SelfRefer(models.Model):
name = models.CharField(max_length=10)
references = models.ManyToManyField('self')
related = models.ManyToManyField('self')
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Tag(models.Model):
name = models.CharField(max_length=10)
- def __unicode__(self):
+ def __str__(self):
return self.name
# Regression for #11956 -- a many to many to the base class
+@python_2_unicode_compatible
class TagCollection(Tag):
tags = models.ManyToManyField(Tag, related_name='tag_collections')
- def __unicode__(self):
+ def __str__(self):
return self.name
# A related_name is required on one of the ManyToManyField entries here because
# they are both addressable as reverse relations from Tag.
+@python_2_unicode_compatible
class Entry(models.Model):
name = models.CharField(max_length=10)
topics = models.ManyToManyField(Tag)
related = models.ManyToManyField(Tag, related_name="similar")
- def __unicode__(self):
+ def __str__(self):
return self.name
# Two models both inheriting from a base model with a self-referential m2m field
diff --git a/tests/regressiontests/m2m_through_regress/models.py b/tests/regressiontests/m2m_through_regress/models.py
index 1db3de1a4c..1995b78984 100644
--- a/tests/regressiontests/m2m_through_regress/models.py
+++ b/tests/regressiontests/m2m_through_regress/models.py
@@ -2,40 +2,45 @@ from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
# Forward declared intermediate model
+@python_2_unicode_compatible
class Membership(models.Model):
person = models.ForeignKey('Person')
group = models.ForeignKey('Group')
price = models.IntegerField(default=100)
- def __unicode__(self):
+ def __str__(self):
return "%s is a member of %s" % (self.person.name, self.group.name)
# using custom id column to test ticket #11107
+@python_2_unicode_compatible
class UserMembership(models.Model):
id = models.AutoField(db_column='usermembership_id', primary_key=True)
user = models.ForeignKey(User)
group = models.ForeignKey('Group')
price = models.IntegerField(default=100)
- def __unicode__(self):
+ def __str__(self):
return "%s is a user and member of %s" % (self.user.username, self.group.name)
+@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=128)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Group(models.Model):
name = models.CharField(max_length=128)
# Membership object defined as a class
members = models.ManyToManyField(Person, through=Membership)
user_members = models.ManyToManyField(User, through='UserMembership')
- def __unicode__(self):
+ def __str__(self):
return self.name
# A set of models that use an non-abstract inherited model as the 'through' model.
diff --git a/tests/regressiontests/managers_regress/models.py b/tests/regressiontests/managers_regress/models.py
index fb6c530722..892505f24a 100644
--- a/tests/regressiontests/managers_regress/models.py
+++ b/tests/regressiontests/managers_regress/models.py
@@ -3,6 +3,7 @@ Various edge-cases for model managers.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class OnlyFred(models.Manager):
@@ -44,35 +45,40 @@ class AbstractBase3(models.Model):
class Meta:
abstract = True
+@python_2_unicode_compatible
class Parent(models.Model):
name = models.CharField(max_length=50)
manager = OnlyFred()
- def __unicode__(self):
+ def __str__(self):
return self.name
# Managers from base classes are inherited and, if no manager is specified
# *and* the parent has a manager specified, the first one (in the MRO) will
# become the default.
+@python_2_unicode_compatible
class Child1(AbstractBase1):
data = models.CharField(max_length=25)
- def __unicode__(self):
+ def __str__(self):
return self.data
+@python_2_unicode_compatible
class Child2(AbstractBase1, AbstractBase2):
data = models.CharField(max_length=25)
- def __unicode__(self):
+ def __str__(self):
return self.data
+@python_2_unicode_compatible
class Child3(AbstractBase1, AbstractBase3):
data = models.CharField(max_length=25)
- def __unicode__(self):
+ def __str__(self):
return self.data
+@python_2_unicode_compatible
class Child4(AbstractBase1):
data = models.CharField(max_length=25)
@@ -80,16 +86,17 @@ class Child4(AbstractBase1):
# inherited.
default = models.Manager()
- def __unicode__(self):
+ def __str__(self):
return self.data
+@python_2_unicode_compatible
class Child5(AbstractBase3):
name = models.CharField(max_length=25)
default = OnlyFred()
objects = models.Manager()
- def __unicode__(self):
+ def __str__(self):
return self.name
# Will inherit managers from AbstractBase1, but not Child4.
diff --git a/tests/regressiontests/many_to_one_regress/models.py b/tests/regressiontests/many_to_one_regress/models.py
index 1e59c4c8c8..f3727820f8 100644
--- a/tests/regressiontests/many_to_one_regress/models.py
+++ b/tests/regressiontests/many_to_one_regress/models.py
@@ -4,6 +4,7 @@ Regression tests for a few ForeignKey bugs.
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
# If ticket #1578 ever slips back in, these models will not be able to be
# created (the field names being lower-cased versions of their opposite
@@ -30,18 +31,20 @@ class Child(models.Model):
# Multiple paths to the same model (#7110, #7125)
+@python_2_unicode_compatible
class Category(models.Model):
name = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Record(models.Model):
category = models.ForeignKey(Category)
+@python_2_unicode_compatible
class Relation(models.Model):
left = models.ForeignKey(Record, related_name='left_set')
right = models.ForeignKey(Record, related_name='right_set')
- def __unicode__(self):
+ def __str__(self):
return "%s - %s" % (self.left.category.name, self.right.category.name)
diff --git a/tests/regressiontests/model_forms_regress/models.py b/tests/regressiontests/model_forms_regress/models.py
index 9259e260f0..f6e08d24dc 100644
--- a/tests/regressiontests/model_forms_regress/models.py
+++ b/tests/regressiontests/model_forms_regress/models.py
@@ -4,6 +4,7 @@ import os
from django.core.exceptions import ValidationError
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class Person(models.Model):
@@ -20,18 +21,20 @@ class Triple(models.Model):
class FilePathModel(models.Model):
path = models.FilePathField(path=os.path.dirname(__file__), match=".*\.py$", blank=True)
+@python_2_unicode_compatible
class Publication(models.Model):
title = models.CharField(max_length=30)
date_published = models.DateField()
- def __unicode__(self):
+ def __str__(self):
return self.title
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)
- def __unicode__(self):
+ def __str__(self):
return self.headline
class CustomFileField(models.FileField):
diff --git a/tests/regressiontests/model_formsets_regress/models.py b/tests/regressiontests/model_formsets_regress/models.py
index 189ed8072e..f94ad51929 100644
--- a/tests/regressiontests/model_formsets_regress/models.py
+++ b/tests/regressiontests/model_formsets_regress/models.py
@@ -1,4 +1,5 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class User(models.Model):
@@ -22,9 +23,10 @@ class Manager(models.Model):
class Network(models.Model):
name = models.CharField(max_length=15)
+@python_2_unicode_compatible
class Host(models.Model):
network = models.ForeignKey(Network)
hostname = models.CharField(max_length=25)
- def __unicode__(self):
+ def __str__(self):
return self.hostname
diff --git a/tests/regressiontests/model_inheritance_regress/models.py b/tests/regressiontests/model_inheritance_regress/models.py
index 5481298963..811c8175bb 100644
--- a/tests/regressiontests/model_inheritance_regress/models.py
+++ b/tests/regressiontests/model_inheritance_regress/models.py
@@ -3,7 +3,9 @@ from __future__ import unicode_literals
import datetime
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
@@ -11,28 +13,31 @@ class Place(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return "%s the place" % self.name
+@python_2_unicode_compatible
class Restaurant(Place):
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return "%s the restaurant" % self.name
+@python_2_unicode_compatible
class ItalianRestaurant(Restaurant):
serves_gnocchi = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return "%s the italian restaurant" % self.name
+@python_2_unicode_compatible
class ParkingLot(Place):
# An explicit link to the parent (we can control the attribute name).
parent = models.OneToOneField(Place, primary_key=True, parent_link=True)
capacity = models.IntegerField()
- def __unicode__(self):
+ def __str__(self):
return "%s the parking lot" % self.name
class ParkingLot2(Place):
@@ -64,13 +69,14 @@ class SelfRefParent(models.Model):
class SelfRefChild(SelfRefParent):
child_data = models.IntegerField()
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100)
pub_date = models.DateTimeField()
class Meta:
ordering = ('-pub_date', 'headline')
- def __unicode__(self):
+ def __str__(self):
return self.headline
class ArticleWithAuthor(Article):
@@ -91,17 +97,19 @@ class Evaluation(Article):
class QualityControl(Evaluation):
assignee = models.CharField(max_length=50)
+@python_2_unicode_compatible
class BaseM(models.Model):
base_name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.base_name
+@python_2_unicode_compatible
class DerivedM(BaseM):
customPK = models.IntegerField(primary_key=True)
derived_name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return "PK = %d, base_name = %s, derived_name = %s" \
% (self.customPK, self.base_name, self.derived_name)
@@ -120,15 +128,17 @@ class InternalCertificationAudit(CertificationAudit):
auditing_dept = models.CharField(max_length=20)
# Check that abstract classes don't get m2m tables autocreated.
+@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=100)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class AbstractEvent(models.Model):
name = models.CharField(max_length=100)
attendees = models.ManyToManyField(Person, related_name="%(class)s_set")
@@ -137,7 +147,7 @@ class AbstractEvent(models.Model):
abstract = True
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
class BirthdayParty(AbstractEvent):
diff --git a/tests/regressiontests/model_inheritance_select_related/models.py b/tests/regressiontests/model_inheritance_select_related/models.py
index f810531bff..6b28772620 100644
--- a/tests/regressiontests/model_inheritance_select_related/models.py
+++ b/tests/regressiontests/model_inheritance_select_related/models.py
@@ -5,27 +5,31 @@ select_related().
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return "%s the place" % self.name
+@python_2_unicode_compatible
class Restaurant(Place):
serves_sushi = models.BooleanField()
serves_steak = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return "%s the restaurant" % self.name
+@python_2_unicode_compatible
class Person(models.Model):
name = models.CharField(max_length=50)
favorite_restaurant = models.ForeignKey(Restaurant)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/regressiontests/model_regress/models.py b/tests/regressiontests/model_regress/models.py
index aca6d44837..6c350d1b5d 100644
--- a/tests/regressiontests/model_regress/models.py
+++ b/tests/regressiontests/model_regress/models.py
@@ -1,5 +1,6 @@
# coding: utf-8
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
CHOICES = (
@@ -8,6 +9,7 @@ CHOICES = (
)
+@python_2_unicode_compatible
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
@@ -20,7 +22,7 @@ class Article(models.Model):
# A utf-8 verbose name (Ångström's Articles) to test they are valid.
verbose_name = "\xc3\x85ngstr\xc3\xb6m's Articles"
- def __unicode__(self):
+ def __str__(self):
return self.headline
@@ -38,26 +40,29 @@ class Event(models.Model):
when = models.DateTimeField()
+@python_2_unicode_compatible
class Department(models.Model):
id = models.PositiveIntegerField(primary_key=True)
name = models.CharField(max_length=200)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Worker(models.Model):
department = models.ForeignKey(Department)
name = models.CharField(max_length=200)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class BrokenUnicodeMethod(models.Model):
name = models.CharField(max_length=7)
- def __unicode__(self):
+ def __str__(self):
# Intentionally broken (trying to insert a unicode value into a str
# object).
return 'Názov: %s' % self.name
diff --git a/tests/regressiontests/modeladmin/models.py b/tests/regressiontests/modeladmin/models.py
index 33202fad8f..fdbcabd187 100644
--- a/tests/regressiontests/modeladmin/models.py
+++ b/tests/regressiontests/modeladmin/models.py
@@ -1,8 +1,10 @@
# coding: utf-8
from django.contrib.auth.models import User
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Band(models.Model):
name = models.CharField(max_length=100)
bio = models.TextField()
@@ -11,7 +13,7 @@ class Band(models.Model):
class Meta:
ordering = ('name',)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Concert(models.Model):
diff --git a/tests/regressiontests/multiple_database/models.py b/tests/regressiontests/multiple_database/models.py
index 7d655fe3d6..e46438649b 100644
--- a/tests/regressiontests/multiple_database/models.py
+++ b/tests/regressiontests/multiple_database/models.py
@@ -4,15 +4,17 @@ from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Review(models.Model):
source = models.CharField(max_length=100)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey()
- def __unicode__(self):
+ def __str__(self):
return self.source
class Meta:
@@ -22,11 +24,12 @@ class PersonManager(models.Manager):
def get_by_natural_key(self, name):
return self.get(name=name)
+@python_2_unicode_compatible
class Person(models.Model):
objects = PersonManager()
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Meta:
@@ -45,6 +48,7 @@ class BookManager(models.Manager):
kwargs.pop('extra_arg', None)
return super(BookManager, self).get_or_create(*args, **kwargs)
+@python_2_unicode_compatible
class Book(models.Model):
objects = BookManager()
title = models.CharField(max_length=100)
@@ -54,17 +58,18 @@ class Book(models.Model):
reviews = generic.GenericRelation(Review)
pages = models.IntegerField(default=100)
- def __unicode__(self):
+ def __str__(self):
return self.title
class Meta:
ordering = ('title',)
+@python_2_unicode_compatible
class Pet(models.Model):
name = models.CharField(max_length=100)
owner = models.ForeignKey(Person)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Meta:
diff --git a/tests/regressiontests/null_fk/models.py b/tests/regressiontests/null_fk/models.py
index e32ff542a0..c86ee8a5a9 100644
--- a/tests/regressiontests/null_fk/models.py
+++ b/tests/regressiontests/null_fk/models.py
@@ -3,6 +3,7 @@ Regression tests for proper working of ForeignKey(null=True).
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
class SystemDetails(models.Model):
@@ -16,13 +17,15 @@ class Forum(models.Model):
system_info = models.ForeignKey(SystemInfo)
forum_name = models.CharField(max_length=32)
+@python_2_unicode_compatible
class Post(models.Model):
forum = models.ForeignKey(Forum, null=True)
title = models.CharField(max_length=32)
- def __unicode__(self):
+ def __str__(self):
return self.title
+@python_2_unicode_compatible
class Comment(models.Model):
post = models.ForeignKey(Post, null=True)
comment_text = models.CharField(max_length=250)
@@ -30,7 +33,7 @@ class Comment(models.Model):
class Meta:
ordering = ('comment_text',)
- def __unicode__(self):
+ def __str__(self):
return self.comment_text
# Ticket 15823
diff --git a/tests/regressiontests/null_fk_ordering/models.py b/tests/regressiontests/null_fk_ordering/models.py
index e4a19f1512..3caff0d594 100644
--- a/tests/regressiontests/null_fk_ordering/models.py
+++ b/tests/regressiontests/null_fk_ordering/models.py
@@ -8,17 +8,19 @@ xpected results
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
# The first two models represent a very simple null FK ordering case.
class Author(models.Model):
name = models.CharField(max_length=150)
+@python_2_unicode_compatible
class Article(models.Model):
title = models.CharField(max_length=150)
author = models.ForeignKey(Author, null=True)
- def __unicode__(self):
+ def __str__(self):
return 'Article titled: %s' % (self.title, )
class Meta:
@@ -33,13 +35,15 @@ class Forum(models.Model):
system_info = models.ForeignKey(SystemInfo)
forum_name = models.CharField(max_length=32)
+@python_2_unicode_compatible
class Post(models.Model):
forum = models.ForeignKey(Forum, null=True)
title = models.CharField(max_length=32)
- def __unicode__(self):
+ def __str__(self):
return self.title
+@python_2_unicode_compatible
class Comment(models.Model):
post = models.ForeignKey(Post, null=True)
comment_text = models.CharField(max_length=250)
@@ -47,5 +51,5 @@ class Comment(models.Model):
class Meta:
ordering = ['post__forum__system_info__system_name', 'comment_text']
- def __unicode__(self):
+ def __str__(self):
return self.comment_text
diff --git a/tests/regressiontests/null_queries/models.py b/tests/regressiontests/null_queries/models.py
index 886bd75276..25560fbab7 100644
--- a/tests/regressiontests/null_queries/models.py
+++ b/tests/regressiontests/null_queries/models.py
@@ -1,19 +1,22 @@
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Poll(models.Model):
question = models.CharField(max_length=200)
- def __unicode__(self):
+ def __str__(self):
return "Q: %s " % self.question
+@python_2_unicode_compatible
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
- def __unicode__(self):
+ def __str__(self):
return "Choice: %s in poll %s" % (self.choice, self.poll)
# A set of models with an inner one pointing to two outer ones.
diff --git a/tests/regressiontests/one_to_one_regress/models.py b/tests/regressiontests/one_to_one_regress/models.py
index 5d32bf03f8..38b801f40e 100644
--- a/tests/regressiontests/one_to_one_regress/models.py
+++ b/tests/regressiontests/one_to_one_regress/models.py
@@ -1,39 +1,44 @@
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Place(models.Model):
name = models.CharField(max_length=50)
address = models.CharField(max_length=80)
- def __unicode__(self):
+ def __str__(self):
return "%s the place" % self.name
+@python_2_unicode_compatible
class Restaurant(models.Model):
place = models.OneToOneField(Place)
serves_hot_dogs = models.BooleanField()
serves_pizza = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return "%s the restaurant" % self.place.name
+@python_2_unicode_compatible
class Bar(models.Model):
place = models.OneToOneField(Place)
serves_cocktails = models.BooleanField()
- def __unicode__(self):
+ def __str__(self):
return "%s the bar" % self.place.name
class UndergroundBar(models.Model):
place = models.OneToOneField(Place, null=True)
serves_cocktails = models.BooleanField()
+@python_2_unicode_compatible
class Favorites(models.Model):
name = models.CharField(max_length = 50)
restaurants = models.ManyToManyField(Restaurant)
- def __unicode__(self):
+ def __str__(self):
return "Favorites for %s" % self.name
class Target(models.Model):
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 6328776e91..45a48ee77c 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -7,6 +7,7 @@ import threading
from django.db import models
from django.utils import six
+from django.utils.encoding import python_2_unicode_compatible
class DumbCategory(models.Model):
@@ -19,6 +20,7 @@ class ProxyCategory(DumbCategory):
class NamedCategory(DumbCategory):
name = models.CharField(max_length=10)
+@python_2_unicode_compatible
class Tag(models.Model):
name = models.CharField(max_length=10)
parent = models.ForeignKey('self', blank=True, null=True,
@@ -28,9 +30,10 @@ class Tag(models.Model):
class Meta:
ordering = ['name']
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Note(models.Model):
note = models.CharField(max_length=100)
misc = models.CharField(max_length=10)
@@ -38,7 +41,7 @@ class Note(models.Model):
class Meta:
ordering = ['note']
- def __unicode__(self):
+ def __str__(self):
return self.note
def __init__(self, *args, **kwargs):
@@ -48,14 +51,16 @@ class Note(models.Model):
# that use objects of that type as an argument.
self.lock = threading.Lock()
+@python_2_unicode_compatible
class Annotation(models.Model):
name = models.CharField(max_length=10)
tag = models.ForeignKey(Tag)
notes = models.ManyToManyField(Note)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class ExtraInfo(models.Model):
info = models.CharField(max_length=100)
note = models.ForeignKey(Note)
@@ -63,9 +68,10 @@ class ExtraInfo(models.Model):
class Meta:
ordering = ['info']
- def __unicode__(self):
+ def __str__(self):
return self.info
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=10)
num = models.IntegerField(unique=True)
@@ -74,9 +80,10 @@ class Author(models.Model):
class Meta:
ordering = ['name']
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Item(models.Model):
name = models.CharField(max_length=10)
created = models.DateTimeField()
@@ -88,16 +95,18 @@ class Item(models.Model):
class Meta:
ordering = ['-note', 'name']
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Report(models.Model):
name = models.CharField(max_length=10)
creator = models.ForeignKey(Author, to_field='num', null=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Ranking(models.Model):
rank = models.IntegerField()
author = models.ForeignKey(Author)
@@ -106,9 +115,10 @@ class Ranking(models.Model):
# A complex ordering specification. Should stress the system a bit.
ordering = ('author__extra__note', 'author__name', 'rank')
- def __unicode__(self):
+ def __str__(self):
return '%d: %s' % (self.rank, self.author.name)
+@python_2_unicode_compatible
class Cover(models.Model):
title = models.CharField(max_length=50)
item = models.ForeignKey(Item)
@@ -116,13 +126,14 @@ class Cover(models.Model):
class Meta:
ordering = ['item']
- def __unicode__(self):
+ def __str__(self):
return self.title
+@python_2_unicode_compatible
class Number(models.Model):
num = models.IntegerField()
- def __unicode__(self):
+ def __str__(self):
return six.text_type(self.num)
# Symmetrical m2m field with a normal field using the reverse accesor name
@@ -168,6 +179,7 @@ class CustomManager(models.Manager):
qs = super(CustomManager, self).get_query_set()
return qs.filter(public=True, tag__name='t1')
+@python_2_unicode_compatible
class ManagedModel(models.Model):
data = models.CharField(max_length=10)
tag = models.ForeignKey(Tag)
@@ -176,7 +188,7 @@ class ManagedModel(models.Model):
objects = CustomManager()
normal_manager = models.Manager()
- def __unicode__(self):
+ def __str__(self):
return self.data
# An inter-related setup with multiple paths from Child to Detail.
@@ -211,11 +223,12 @@ class Related(models.Model):
# An inter-related setup with a model subclass that has a nullable
# path to another model, and a return path from that model.
+@python_2_unicode_compatible
class Celebrity(models.Model):
name = models.CharField("Name", max_length=20)
greatest_fan = models.ForeignKey("Fan", null=True, unique=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
class TvChef(Celebrity):
@@ -225,10 +238,11 @@ class Fan(models.Model):
fan_of = models.ForeignKey(Celebrity)
# Multiple foreign keys
+@python_2_unicode_compatible
class LeafA(models.Model):
data = models.CharField(max_length=10)
- def __unicode__(self):
+ def __str__(self):
return self.data
class LeafB(models.Model):
@@ -238,11 +252,12 @@ class Join(models.Model):
a = models.ForeignKey(LeafA)
b = models.ForeignKey(LeafB)
+@python_2_unicode_compatible
class ReservedName(models.Model):
name = models.CharField(max_length=20)
order = models.IntegerField()
- def __unicode__(self):
+ def __str__(self):
return self.name
# A simpler shared-foreign-key setup that can expose some problems.
@@ -256,13 +271,14 @@ class PointerB(models.Model):
connection = models.ForeignKey(SharedConnection)
# Multi-layer ordering
+@python_2_unicode_compatible
class SingleObject(models.Model):
name = models.CharField(max_length=10)
class Meta:
ordering = ['name']
- def __unicode__(self):
+ def __str__(self):
return self.name
class RelatedObject(models.Model):
@@ -271,6 +287,7 @@ class RelatedObject(models.Model):
class Meta:
ordering = ['single']
+@python_2_unicode_compatible
class Plaything(models.Model):
name = models.CharField(max_length=10)
others = models.ForeignKey(RelatedObject, null=True)
@@ -278,79 +295,89 @@ class Plaything(models.Model):
class Meta:
ordering = ['others']
- def __unicode__(self):
+ def __str__(self):
return self.name
class Article(models.Model):
name = models.CharField(max_length=20)
created = models.DateTimeField()
+@python_2_unicode_compatible
class Food(models.Model):
name = models.CharField(max_length=20, unique=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Eaten(models.Model):
food = models.ForeignKey(Food, to_field="name")
meal = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return "%s at %s" % (self.food, self.meal)
+@python_2_unicode_compatible
class Node(models.Model):
num = models.IntegerField(unique=True)
parent = models.ForeignKey("self", to_field="num", null=True)
- def __unicode__(self):
+ def __str__(self):
return "%s" % self.num
# Bug #12252
+@python_2_unicode_compatible
class ObjectA(models.Model):
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class ObjectB(models.Model):
name = models.CharField(max_length=50)
objecta = models.ForeignKey(ObjectA)
num = models.PositiveSmallIntegerField()
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class ObjectC(models.Model):
name = models.CharField(max_length=50)
objecta = models.ForeignKey(ObjectA)
objectb = models.ForeignKey(ObjectB)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class SimpleCategory(models.Model):
name = models.CharField(max_length=15)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class SpecialCategory(SimpleCategory):
special_name = models.CharField(max_length=15)
- def __unicode__(self):
+ def __str__(self):
return self.name + " " + self.special_name
+@python_2_unicode_compatible
class CategoryItem(models.Model):
category = models.ForeignKey(SimpleCategory)
- def __unicode__(self):
+ def __str__(self):
return "category item: " + str(self.category)
+@python_2_unicode_compatible
class OneToOneCategory(models.Model):
new_name = models.CharField(max_length=15)
category = models.OneToOneField(SimpleCategory)
- def __unicode__(self):
+ def __str__(self):
return "one2one " + self.new_name
class NullableName(models.Model):
diff --git a/tests/regressiontests/select_related_onetoone/models.py b/tests/regressiontests/select_related_onetoone/models.py
index 3d6da9b4c5..3284defb11 100644
--- a/tests/regressiontests/select_related_onetoone/models.py
+++ b/tests/regressiontests/select_related_onetoone/models.py
@@ -1,44 +1,50 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class User(models.Model):
username = models.CharField(max_length=100)
email = models.EmailField()
- def __unicode__(self):
+ def __str__(self):
return self.username
+@python_2_unicode_compatible
class UserProfile(models.Model):
user = models.OneToOneField(User)
city = models.CharField(max_length=100)
state = models.CharField(max_length=2)
- def __unicode__(self):
+ def __str__(self):
return "%s, %s" % (self.city, self.state)
+@python_2_unicode_compatible
class UserStatResult(models.Model):
results = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return 'UserStatResults, results = %s' % (self.results,)
+@python_2_unicode_compatible
class UserStat(models.Model):
user = models.OneToOneField(User, primary_key=True)
posts = models.IntegerField()
results = models.ForeignKey(UserStatResult)
- def __unicode__(self):
+ def __str__(self):
return 'UserStat, posts = %s' % (self.posts,)
+@python_2_unicode_compatible
class StatDetails(models.Model):
base_stats = models.OneToOneField(UserStat)
comments = models.IntegerField()
- def __unicode__(self):
+ def __str__(self):
return 'StatDetails, comments = %s' % (self.comments,)
diff --git a/tests/regressiontests/select_related_regress/models.py b/tests/regressiontests/select_related_regress/models.py
index 1af9ff4bca..a291a547f7 100644
--- a/tests/regressiontests/select_related_regress/models.py
+++ b/tests/regressiontests/select_related_regress/models.py
@@ -1,34 +1,39 @@
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Building(models.Model):
name = models.CharField(max_length=10)
- def __unicode__(self):
+ def __str__(self):
return "Building: %s" % self.name
+@python_2_unicode_compatible
class Device(models.Model):
building = models.ForeignKey('Building')
name = models.CharField(max_length=10)
- def __unicode__(self):
+ def __str__(self):
return "device '%s' in building %s" % (self.name, self.building)
+@python_2_unicode_compatible
class Port(models.Model):
device = models.ForeignKey('Device')
port_number = models.CharField(max_length=10)
- def __unicode__(self):
+ def __str__(self):
return "%s/%s" % (self.device.name, self.port_number)
+@python_2_unicode_compatible
class Connection(models.Model):
start = models.ForeignKey(Port, related_name='connection_start',
unique=True)
end = models.ForeignKey(Port, related_name='connection_end', unique=True)
- def __unicode__(self):
+ def __str__(self):
return "%s to %s" % (self.start, self.end)
# Another non-tree hierarchy that exercises code paths similar to the above
@@ -72,18 +77,20 @@ class SpecialClient(Client):
value = models.IntegerField()
# Some model inheritance exercises
+@python_2_unicode_compatible
class Parent(models.Model):
name = models.CharField(max_length=10)
- def __unicode__(self):
+ def __str__(self):
return self.name
class Child(Parent):
value = models.IntegerField()
+@python_2_unicode_compatible
class Item(models.Model):
name = models.CharField(max_length=10)
child = models.ForeignKey(Child, null=True)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/regressiontests/signals_regress/models.py b/tests/regressiontests/signals_regress/models.py
index bf64f69e8c..829314c06c 100644
--- a/tests/regressiontests/signals_regress/models.py
+++ b/tests/regressiontests/signals_regress/models.py
@@ -1,15 +1,18 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=20)
- def __unicode__(self):
+ def __str__(self):
return self.name
+@python_2_unicode_compatible
class Book(models.Model):
name = models.CharField(max_length=20)
authors = models.ManyToManyField(Author)
- def __unicode__(self):
+ def __str__(self):
return self.name
diff --git a/tests/regressiontests/sites_framework/models.py b/tests/regressiontests/sites_framework/models.py
index 9ecc3e6660..55c4f4992e 100644
--- a/tests/regressiontests/sites_framework/models.py
+++ b/tests/regressiontests/sites_framework/models.py
@@ -1,7 +1,9 @@
from django.contrib.sites.managers import CurrentSiteManager
from django.contrib.sites.models import Site
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class AbstractArticle(models.Model):
title = models.CharField(max_length=50)
@@ -11,7 +13,7 @@ class AbstractArticle(models.Model):
class Meta:
abstract = True
- def __unicode__(self):
+ def __str__(self):
return self.title
class SyndicatedArticle(AbstractArticle):
diff --git a/tests/regressiontests/string_lookup/models.py b/tests/regressiontests/string_lookup/models.py
index 0704890cd7..a2d64cd0b2 100644
--- a/tests/regressiontests/string_lookup/models.py
+++ b/tests/regressiontests/string_lookup/models.py
@@ -2,47 +2,54 @@
from __future__ import unicode_literals
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Foo(models.Model):
name = models.CharField(max_length=50)
friend = models.CharField(max_length=50, blank=True)
- def __unicode__(self):
+ def __str__(self):
return "Foo %s" % self.name
+@python_2_unicode_compatible
class Bar(models.Model):
name = models.CharField(max_length=50)
normal = models.ForeignKey(Foo, related_name='normal_foo')
fwd = models.ForeignKey("Whiz")
back = models.ForeignKey("Foo")
- def __unicode__(self):
+ def __str__(self):
return "Bar %s" % self.place.name
+@python_2_unicode_compatible
class Whiz(models.Model):
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return "Whiz %s" % self.name
+@python_2_unicode_compatible
class Child(models.Model):
parent = models.OneToOneField('Base')
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return "Child %s" % self.name
+@python_2_unicode_compatible
class Base(models.Model):
name = models.CharField(max_length=50)
- def __unicode__(self):
+ def __str__(self):
return "Base %s" % self.name
+@python_2_unicode_compatible
class Article(models.Model):
name = models.CharField(max_length=50)
text = models.TextField()
submitted_from = models.IPAddressField(blank=True, null=True)
- def __unicode__(self):
+ def __str__(self):
return "Article %s" % self.name
diff --git a/tests/regressiontests/syndication/models.py b/tests/regressiontests/syndication/models.py
index a2c504e57f..10b3fe3a0c 100644
--- a/tests/regressiontests/syndication/models.py
+++ b/tests/regressiontests/syndication/models.py
@@ -1,6 +1,8 @@
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Entry(models.Model):
title = models.CharField(max_length=200)
date = models.DateTimeField()
@@ -8,17 +10,18 @@ class Entry(models.Model):
class Meta:
ordering = ('date',)
- def __unicode__(self):
+ def __str__(self):
return self.title
def get_absolute_url(self):
return "/blog/%s/" % self.pk
+@python_2_unicode_compatible
class Article(models.Model):
title = models.CharField(max_length=200)
entry = models.ForeignKey(Entry)
- def __unicode__(self):
+ def __str__(self):
return self.title
diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py
index fd570700af..606282ecc5 100644
--- a/tests/regressiontests/templates/filters.py
+++ b/tests/regressiontests/templates/filters.py
@@ -13,14 +13,17 @@ from datetime import date, datetime, timedelta
from django.test.utils import str_prefix
from django.utils.tzinfo import LocalTimezone, FixedOffset
from django.utils.safestring import mark_safe
+from django.utils.encoding import python_2_unicode_compatible
# These two classes are used to test auto-escaping of __unicode__ output.
+@python_2_unicode_compatible
class UnsafeClass:
- def __unicode__(self):
+ def __str__(self):
return 'you & me'
+@python_2_unicode_compatible
class SafeClass:
- def __unicode__(self):
+ def __str__(self):
return mark_safe('you &gt; me')
# RESULT SYNTAX --
@@ -338,11 +341,11 @@ def get_filter_tests():
'join04': (r'{% autoescape off %}{{ a|join:" &amp; " }}{% endautoescape %}', {'a': ['alpha', 'beta & me']}, 'alpha &amp; beta & me'),
# Test that joining with unsafe joiners don't result in unsafe strings (#11377)
- 'join05': (r'{{ a|join:var }}', {'a': ['alpha', 'beta & me'], 'var': ' & '}, 'alpha &amp; beta &amp; me'),
- 'join06': (r'{{ a|join:var }}', {'a': ['alpha', 'beta & me'], 'var': mark_safe(' & ')}, 'alpha & beta &amp; me'),
- 'join07': (r'{{ a|join:var|lower }}', {'a': ['Alpha', 'Beta & me'], 'var': ' & ' }, 'alpha &amp; beta &amp; me'),
- 'join08': (r'{{ a|join:var|lower }}', {'a': ['Alpha', 'Beta & me'], 'var': mark_safe(' & ')}, 'alpha & beta &amp; me'),
-
+ 'join05': (r'{{ a|join:var }}', {'a': ['alpha', 'beta & me'], 'var': ' & '}, 'alpha &amp; beta &amp; me'),
+ 'join06': (r'{{ a|join:var }}', {'a': ['alpha', 'beta & me'], 'var': mark_safe(' & ')}, 'alpha & beta &amp; me'),
+ 'join07': (r'{{ a|join:var|lower }}', {'a': ['Alpha', 'Beta & me'], 'var': ' & ' }, 'alpha &amp; beta &amp; me'),
+ 'join08': (r'{{ a|join:var|lower }}', {'a': ['Alpha', 'Beta & me'], 'var': mark_safe(' & ')}, 'alpha & beta &amp; me'),
+
'date01': (r'{{ d|date:"m" }}', {'d': datetime(2008, 1, 1)}, '01'),
'date02': (r'{{ d|date }}', {'d': datetime(2008, 1, 1)}, 'Jan. 1, 2008'),
#Ticket 9520: Make sure |date doesn't blow up on non-dates
diff --git a/tests/regressiontests/views/models.py b/tests/regressiontests/views/models.py
index 54f5c1c1f0..461f98c028 100644
--- a/tests/regressiontests/views/models.py
+++ b/tests/regressiontests/views/models.py
@@ -3,16 +3,19 @@ Regression tests for Django built-in views.
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
+@python_2_unicode_compatible
class Author(models.Model):
name = models.CharField(max_length=100)
- def __unicode__(self):
+ def __str__(self):
return self.name
def get_absolute_url(self):
return '/views/authors/%s/' % self.id
+@python_2_unicode_compatible
class BaseArticle(models.Model):
"""
An abstract article Model so that we can create article models with and
@@ -25,7 +28,7 @@ class BaseArticle(models.Model):
class Meta:
abstract = True
- def __unicode__(self):
+ def __str__(self):
return self.title
class Article(BaseArticle):