Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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
  • Loading branch information...
commit d4a0b27838c815af87698920cc4db7d2afd6f05b 1 parent 79d62a7
@aaugustin aaugustin authored
Showing with 1,072 additions and 481 deletions.
  1. +3 −1 django/contrib/admin/models.py
  2. +9 −4 django/contrib/auth/models.py
  3. +5 −2 django/contrib/comments/models.py
  4. +3 −1 django/contrib/contenttypes/models.py
  5. +3 −1 django/contrib/contenttypes/tests.py
  6. +3 −1 django/contrib/databrowse/datastructures.py
  7. +7 −3 django/contrib/databrowse/tests.py
  8. +3 −1 django/contrib/flatpages/models.py
  9. +3 −1 django/contrib/gis/db/backends/base.py
  10. +3 −1 django/contrib/gis/db/backends/oracle/models.py
  11. +3 −1 django/contrib/gis/db/backends/postgis/models.py
  12. +3 −1 django/contrib/gis/db/backends/spatialite/models.py
  13. +5 −2 django/contrib/gis/maps/google/overlays.py
  14. +15 −7 django/contrib/gis/tests/distapp/models.py
  15. +17 −9 django/contrib/gis/tests/geo3d/models.py
  16. +3 −1 django/contrib/gis/tests/geoadmin/models.py
  17. +11 −5 django/contrib/gis/tests/geoapp/models.py
  18. +7 −3 django/contrib/gis/tests/geogapp/models.py
  19. +9 −5 django/contrib/gis/tests/relatedapp/models.py
  20. +1 −1  django/contrib/gis/utils/ogrinspect.py
  21. +4 −3 django/contrib/messages/storage/base.py
  22. +4 −2 django/contrib/redirects/models.py
  23. +5 −2 django/contrib/sites/models.py
  24. +5 −2 django/core/files/base.py
  25. +3 −1 django/core/files/uploadhandler.py
  26. +3 −1 django/db/models/options.py
  27. +7 −5 django/forms/forms.py
  28. +4 −3 django/forms/formsets.py
  29. +7 −5 django/forms/util.py
  30. +12 −8 django/forms/widgets.py
  31. +3 −1 django/template/base.py
  32. +5 −2 django/test/html.py
  33. +9 −4 tests/modeltests/aggregation/models.py
  34. +3 −1 tests/modeltests/basic/models.py
  35. +3 −1 tests/modeltests/choices/models.py
  36. +5 −2 tests/modeltests/custom_columns/models.py
  37. +7 −3 tests/modeltests/custom_managers/models.py
  38. +3 −1 tests/modeltests/custom_methods/models.py
  39. +3 −1 tests/modeltests/custom_pk/fields.py
  40. +7 −3 tests/modeltests/custom_pk/models.py
  41. +3 −1 tests/modeltests/defer/models.py
  42. +3 −1 tests/modeltests/delete/models.py
  43. +9 −4 tests/modeltests/distinct_on_fields/models.py
  44. +5 −2 tests/modeltests/expressions/models.py
  45. +3 −1 tests/modeltests/field_defaults/models.py
  46. +3 −1 tests/modeltests/field_subclassing/fields.py
  47. +3 −1 tests/modeltests/field_subclassing/models.py
  48. +15 −7 tests/modeltests/fixtures/models.py
  49. +3 −1 tests/modeltests/fixtures_model_package/models/__init__.py
  50. +11 −5 tests/modeltests/generic_relations/models.py
  51. +5 −2 tests/modeltests/get_latest/models.py
  52. +5 −2 tests/modeltests/get_object_or_404/models.py
  53. +3 −1 tests/modeltests/get_or_create/models.py
  54. +9 −4 tests/modeltests/lookup/models.py
  55. +3 −1 tests/modeltests/m2m_and_m2o/models.py
  56. +7 −3 tests/modeltests/m2m_intermediary/models.py
  57. +5 −2 tests/modeltests/m2m_multiple/models.py
  58. +3 −1 tests/modeltests/m2m_recursive/models.py
  59. +7 −3 tests/modeltests/m2m_signals/models.py
  60. +11 −5 tests/modeltests/m2m_through/models.py
  61. +5 −2 tests/modeltests/m2o_recursive/models.py
  62. +5 −2 tests/modeltests/many_to_many/models.py
  63. +5 −2 tests/modeltests/many_to_one/models.py
  64. +5 −2 tests/modeltests/many_to_one_null/models.py
  65. +31 −15 tests/modeltests/model_forms/models.py
  66. +37 −18 tests/modeltests/model_formsets/models.py
  67. +19 −9 tests/modeltests/model_inheritance/models.py
  68. +3 −1 tests/modeltests/model_inheritance_same_model_name/models.py
  69. +9 −4 tests/modeltests/one_to_one/models.py
  70. +3 −1 tests/modeltests/or_lookups/models.py
  71. +5 −2 tests/modeltests/order_with_respect_to/models.py
  72. +5 −2 tests/modeltests/ordering/models.py
  73. +3 −1 tests/modeltests/pagination/models.py
  74. +15 −7 tests/modeltests/prefetch_related/models.py
  75. +9 −4 tests/modeltests/proxy_models/models.py
  76. +4 −2 tests/modeltests/reserved_names/models.py
  77. +7 −3 tests/modeltests/reverse_lookup/models.py
  78. +3 −1 tests/modeltests/save_delete_hooks/models.py
  79. +18 −9 tests/modeltests/select_related/models.py
  80. +17 −8 tests/modeltests/serializers/models.py
  81. +5 −2 tests/modeltests/signals/models.py
  82. +4 −2 tests/modeltests/str/models.py
  83. +3 −1 tests/modeltests/transactions/models.py
  84. +13 −6 tests/modeltests/unmanaged_models/models.py
  85. +5 −2 tests/modeltests/update/models.py
  86. +5 −2 tests/modeltests/update_only_fields/models.py
  87. +3 −1 tests/modeltests/validation/models.py
  88. +5 −2 tests/regressiontests/admin_changelist/models.py
  89. +3 −1 tests/regressiontests/admin_custom_urls/models.py
  90. +7 −3 tests/regressiontests/admin_filters/models.py
  91. +7 −3 tests/regressiontests/admin_inlines/models.py
  92. +3 −1 tests/regressiontests/admin_scripts/models.py
  93. +3 −1 tests/regressiontests/admin_util/models.py
  94. +3 −1 tests/regressiontests/admin_validation/models.py
  95. +61 −30 tests/regressiontests/admin_views/models.py
  96. +16 −8 tests/regressiontests/admin_widgets/models.py
  97. +11 −5 tests/regressiontests/aggregation_regress/models.py
  98. +9 −4 tests/regressiontests/backends/models.py
  99. +7 −3 tests/regressiontests/comment_tests/models.py
  100. +5 −2 tests/regressiontests/custom_columns_regress/models.py
  101. +7 −3 tests/regressiontests/custom_managers_regress/models.py
  102. +3 −1 tests/regressiontests/datatypes/models.py
  103. +5 −2 tests/regressiontests/dates/models.py
  104. +3 −1 tests/regressiontests/defaultfilters/tests.py
  105. +7 −3 tests/regressiontests/defer_regress/models.py
  106. +3 −1 tests/regressiontests/expressions_regress/models.py
  107. +5 −2 tests/regressiontests/extra_regress/models.py
  108. +17 −8 tests/regressiontests/fixtures_regress/models.py
  109. +5 −2 tests/regressiontests/forms/models.py
  110. +3 −1 tests/regressiontests/forms/tests/error_messages.py
  111. +20 −8 tests/regressiontests/forms/tests/extra.py
  112. +3 −1 tests/regressiontests/forms/tests/util.py
  113. +5 −2 tests/regressiontests/forms/tests/widgets.py
  114. +3 −1 tests/regressiontests/generic_inline_admin/models.py
  115. +11 −5 tests/regressiontests/generic_relations_regress/models.py
  116. +7 −3 tests/regressiontests/generic_views/models.py
  117. +5 −2 tests/regressiontests/inline_formsets/models.py
  118. +5 −2 tests/regressiontests/introspection/models.py
  119. +9 −4 tests/regressiontests/m2m_regress/models.py
  120. +9 −4 tests/regressiontests/m2m_through_regress/models.py
  121. +13 −6 tests/regressiontests/managers_regress/models.py
  122. +5 −2 tests/regressiontests/many_to_one_regress/models.py
  123. +5 −2 tests/regressiontests/model_forms_regress/models.py
  124. +3 −1 tests/regressiontests/model_formsets_regress/models.py
  125. +19 −9 tests/regressiontests/model_inheritance_regress/models.py
  126. +7 −3 tests/regressiontests/model_inheritance_select_related/models.py
  127. +9 −4 tests/regressiontests/model_regress/models.py
  128. +3 −1 tests/regressiontests/modeladmin/models.py
  129. +9 −4 tests/regressiontests/multiple_database/models.py
  130. +5 −2 tests/regressiontests/null_fk/models.py
  131. +7 −3 tests/regressiontests/null_fk_ordering/models.py
  132. +5 −2 tests/regressiontests/null_queries/models.py
  133. +9 −4 tests/regressiontests/one_to_one_regress/models.py
  134. +53 −26 tests/regressiontests/queries/models.py
  135. +11 −5 tests/regressiontests/select_related_onetoone/models.py
  136. +13 −6 tests/regressiontests/select_related_regress/models.py
  137. +5 −2 tests/regressiontests/signals_regress/models.py
  138. +3 −1 tests/regressiontests/sites_framework/models.py
  139. +13 −6 tests/regressiontests/string_lookup/models.py
  140. +5 −2 tests/regressiontests/syndication/models.py
  141. +10 −7 tests/regressiontests/templates/filters.py
  142. +5 −2 tests/regressiontests/views/models.py
View
4 django/contrib/admin/models.py
@@ -6,6 +6,7 @@
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 @@ def log_action(self, user_id, content_type_id, object_id, object_repr, action_fl
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 Meta:
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:
View
13 django/contrib/auth/models.py
@@ -16,6 +16,7 @@
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 @@ def get_by_natural_key(self, codename, app_label, model):
)
+@python_2_unicode_compatible
class Permission(models.Model):
"""
The permissions system provides a way to assign permissions to specific
@@ -76,7 +78,7 @@ class Meta:
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 Meta:
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 Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
- def __unicode__(self):
+ def __str__(self):
return self.username
def natural_key(self):
@@ -403,6 +407,7 @@ def get_profile(self):
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):
View
7 django/contrib/comments/models.py
@@ -8,6 +8,7 @@
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 @@ def get_content_object_url(self):
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 Meta:
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 @@ def get_as_text(self):
}
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 Meta:
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)
View
4 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 @@ def _add_to_cache(self, using, ct):
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 Meta:
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
View
4 django/contrib/contenttypes/tests.py
@@ -8,6 +8,7 @@
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
View
4 django/contrib/databrowse/datastructures.py
@@ -9,6 +9,7 @@
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 @@ def __repr__(self):
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 @@ def __init__(self, easy_model, instance):
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] + '...'
View
10 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
View
4 django/contrib/flatpages/models.py
@@ -3,8 +3,10 @@
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 Meta:
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):
View
4 django/contrib/gis/db/backends/base.py
@@ -5,6 +5,7 @@
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 @@ def geometry_columns(self):
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 @@ def get_spheroid(cls, wkt, string=True):
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.
View
4 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 @@ def geom_col_name(cls):
"""
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):
View
4 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 @@ def geom_col_name(cls):
"""
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)
View
4 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 @@ def geom_col_name(cls):
"""
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)
View
7 django/contrib/gis/maps/google/overlays.py
@@ -2,8 +2,10 @@
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 @@ def __init__(self, event, action):
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 @@ def add_event(self, event):
"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))
View
22 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
View
26 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):
View
4 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)
View
16 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.
View
10 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])
View
14 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):
View
2  django/contrib/gis/utils/ogrinspect.py
@@ -223,4 +223,4 @@ def get_kwargs_str(field_name):
if name_field:
yield ''
- yield ' def __unicode__(self): return self.%s' % name_field
+ yield ' def __str__(self): return self.%s' % name_field
View
7 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 @@ def __eq__(self, other):
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):
View
6 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 Meta:
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)
View
7 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 @@ def clear_cache(self):
SITE_CACHE = {}
+@python_2_unicode_compatible
class Site(models.Model):
domain = models.CharField(_('domain name'), max_length=100)
@@ -44,7 +46,7 @@ class Meta:
verbose_name_plural = _('sites')
ordering = ('domain',)
- def __unicode__(self):
+ def __str__(self):
return self.domain
def save(self, *args, **kwargs):
@@ -62,6 +64,7 @@ def delete(self):
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):
View
7 django/core/files/base.py
@@ -5,7 +5,9 @@
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 @@ def __init__(self, file, name=None):
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 @@ def open(self, mode=None):
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 @@ def __init__(self, content, name=None):
super(ContentFile, self).__init__(BytesIO(content), name=name)
self.size = len(content)
- def __unicode__(self):
+ def __str__(self):
return 'Raw content'
def __bool__(self):
View
4 django/core/files/uploadhandler.py
@@ -10,6 +10,7 @@
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 @@ def __init__(self, connection_reset=False):
"""
self.connection_reset = connection_reset
- def __unicode__(self):
+ def __str__(self):
if self.connection_reset:
return 'StopUpload: Halt current upload.'
else:
View
4 django/db/models/options.py
@@ -13,6 +13,7 @@
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 @@
'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 @@ def setup_proxy(self, target):
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):
View
12 django/forms/forms.py
@@ -12,7 +12,7 @@
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 @@ def __new__(cls, name, bases, attrs):
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 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
# 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 @@ def __init__(self, form, field, name):
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)
View
7 django/forms/formsets.py
@@ -5,7 +5,7 @@
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 @@ def __init__(self, *args, **kwargs):
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 @@ def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
# construct the forms in the formset
self._construct_forms()
- def __unicode__(self):
+ def __str__(self):
return self.as_table()
def __iter__(self):
View
12 django/forms/util.py
@@ -2,7 +2,7 @@
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 @@ def as_ul(self):
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):
View
20 django/forms/widgets.py
@@ -17,7 +17,7 @@
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 @@
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 @@ def __init__(self, media=None, **kwargs):
# 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 @@ def __new__(cls, name, bases, attrs):
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 @@ def __init__(self, parent_widget, name, value, attrs, choices):
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 @@ def _has_changed(self, initial, data):
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 @@ def __init__(self, name, value, attrs, choice, index):
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 @@ def tag(self):
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 @@ def __getitem__(self, idx):
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):
View
4 django/template/base.py
@@ -20,6 +20,7 @@
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])
View
7 django/test/html.py
@@ -8,6 +8,7 @@
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 @@ def count(self, element):
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 @@ def __repr__(self):
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)
View
13 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
View
4 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
View
4 tests/modeltests/choices/models.py
@@ -10,6 +10,7 @@
"""
from django.db import models
+from django.utils.encoding import python_2_unicode_compatible
GENDER_CHOICES = (
@@ -17,9 +18,10 @@
('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
View
7 tests/modeltests/custom_columns/models.py
@@ -18,24 +18,27 @@
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:
View
10 tests/modeltests/custom_managers/models.py
@@ -12,6 +12,7 @@
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
View
4 tests/modeltests/custom_methods/models.py
@@ -7,13 +7,15 @@
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):
View
4 tests/modeltests/custom_pk/fields.py
@@ -3,8 +3,10 @@
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 @@ def __init__(self, value):
def __repr__(self):
return "<%s: %s>" % (self.__class__.__name__, self.value)
- def __unicode__(self):
+ def __str__(self):
return self.value
def __eq__(self, other):
View
10 tests/modeltests/custom_pk/models.py
@@ -11,8 +11,10 @@
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)
View
4 tests/modeltests/defer/models.py
@@ -3,18 +3,20 @@
"""
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):
View
4 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
View
13 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)
View
7 tests/modeltests/expressions/models.py
@@ -4,15 +4,18 @@
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
View
4 tests/modeltests/field_defaults/models.py
@@ -13,11 +13,13 @@
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
View
4 tests/modeltests/field_subclassing/fields.py
@@ -5,8 +5,10 @@
from django.db import models
from django.utils.encoding