diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-08-12 12:32:08 +0200 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-08-12 14:44:40 +0200 |
| commit | d4a0b27838c815af87698920cc4db7d2afd6f05b (patch) | |
| tree | 6fedc7203389ab1f80f8cc7e913230c51e9b8776 /tests/regressiontests/admin_widgets | |
| parent | 79d62a71751140315227891bbe175630f9d3edc3 (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/regressiontests/admin_widgets')
| -rw-r--r-- | tests/regressiontests/admin_widgets/models.py | 24 |
1 files changed, 16 insertions, 8 deletions
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 |
