summaryrefslogtreecommitdiff
path: root/tests/modeltests/model_inheritance/models.py
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 /tests/modeltests/model_inheritance/models.py
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
Diffstat (limited to 'tests/modeltests/model_inheritance/models.py')
-rw-r--r--tests/modeltests/model_inheritance/models.py28
1 files changed, 19 insertions, 9 deletions
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):