From 555e3a848e7ac13580371c7eafbc89195fee6ea9 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 30 Apr 2020 09:13:23 +0200 Subject: [PATCH] Removed unused __str__() methods in tests models. Follow up to 6461583b6cc257d25880ef9a9fd7e2125ac53ce1. --- tests/aggregation_regress/models.py | 15 --------- tests/annotations/models.py | 5 --- tests/contenttypes_tests/models.py | 24 -------------- tests/custom_managers/models.py | 18 ----------- tests/custom_pk/models.py | 6 ---- tests/db_functions/models.py | 12 ------- tests/defer_regress/models.py | 9 ------ tests/delete/models.py | 3 -- tests/expressions/models.py | 3 -- tests/expressions_case/models.py | 12 ------- tests/expressions_window/models.py | 3 -- tests/extra_regress/models.py | 3 -- tests/filtered_relation/models.py | 18 ----------- tests/generic_relations_regress/models.py | 24 ++------------ tests/get_or_create/models.py | 3 -- tests/lookup/models.py | 6 ---- tests/m2m_intermediary/models.py | 6 ---- tests/m2m_signals/models.py | 9 ------ tests/m2m_through/models.py | 15 --------- tests/m2m_through_regress/models.py | 6 ---- tests/many_to_one/models.py | 3 -- tests/many_to_one_null/models.py | 3 -- tests/model_inheritance/models.py | 21 ------------ tests/model_inheritance_regress/models.py | 31 ------------------ tests/model_regress/models.py | 6 ---- tests/multiple_database/models.py | 3 -- tests/null_fk_ordering/models.py | 9 ------ tests/null_queries/models.py | 6 ---- tests/one_to_one/models.py | 6 ---- tests/ordering/models.py | 3 -- tests/prefetch_related/models.py | 21 ------------ tests/reverse_lookup/models.py | 9 ------ tests/select_related/models.py | 39 ----------------------- tests/select_related_onetoone/models.py | 27 ---------------- tests/select_related_regress/models.py | 15 --------- 35 files changed, 2 insertions(+), 400 deletions(-) diff --git a/tests/aggregation_regress/models.py b/tests/aggregation_regress/models.py index 3498cbf168..f7b42a229e 100644 --- a/tests/aggregation_regress/models.py +++ b/tests/aggregation_regress/models.py @@ -10,17 +10,11 @@ class Author(models.Model): age = models.IntegerField() friends = models.ManyToManyField('self', blank=True) - def __str__(self): - return self.name - class Publisher(models.Model): name = models.CharField(max_length=255) num_awards = models.IntegerField() - def __str__(self): - return self.name - class ItemTag(models.Model): tag = models.CharField(max_length=100) @@ -44,9 +38,6 @@ class Book(models.Model): class Meta: ordering = ('name',) - def __str__(self): - return self.name - class Store(models.Model): name = models.CharField(max_length=255) @@ -54,9 +45,6 @@ class Store(models.Model): original_opening = models.DateTimeField() friday_night_closing = models.TimeField() - def __str__(self): - return self.name - class Entries(models.Model): EntryID = models.AutoField(primary_key=True, db_column='Entry ID') @@ -81,9 +69,6 @@ class WithManualPK(models.Model): class HardbackBook(Book): weight = models.FloatField() - def __str__(self): - return "%s (hardback): %s" % (self.name, self.weight) - # Models for ticket #21150 class Alfa(models.Model): diff --git a/tests/annotations/models.py b/tests/annotations/models.py index c8fbe17792..500240df9b 100644 --- a/tests/annotations/models.py +++ b/tests/annotations/models.py @@ -54,11 +54,6 @@ class Company(models.Model): ticker_name = models.CharField(max_length=10, null=True, blank=True) description = models.CharField(max_length=200, null=True, blank=True) - def __str__(self): - return 'Company(name=%s, motto=%s, ticker_name=%s, description=%s)' % ( - self.name, self.motto, self.ticker_name, self.description, - ) - class Ticket(models.Model): active_at = models.DateTimeField() diff --git a/tests/contenttypes_tests/models.py b/tests/contenttypes_tests/models.py index eeab6296ee..2e0640459f 100644 --- a/tests/contenttypes_tests/models.py +++ b/tests/contenttypes_tests/models.py @@ -12,16 +12,10 @@ class Site(models.Model): domain = models.CharField(max_length=100) objects = SiteManager() - def __str__(self): - return self.domain - class Author(models.Model): name = models.CharField(max_length=100) - def __str__(self): - return self.name - def get_absolute_url(self): return '/authors/%s/' % self.id @@ -32,16 +26,10 @@ class Article(models.Model): author = models.ForeignKey(Author, models.CASCADE) date_created = models.DateTimeField() - def __str__(self): - return self.title - class SchemeIncludedURL(models.Model): url = models.URLField(max_length=100) - def __str__(self): - return self.url - def get_absolute_url(self): return self.url @@ -62,9 +50,6 @@ class FooWithoutUrl(models.Model): """ name = models.CharField(max_length=30, unique=True) - def __str__(self): - return self.name - class FooWithUrl(FooWithoutUrl): """ @@ -99,9 +84,6 @@ class Answer(models.Model): class Meta: order_with_respect_to = 'question' - def __str__(self): - return self.text - class Post(models.Model): """An ordered tag on an item.""" @@ -114,18 +96,12 @@ class Post(models.Model): class Meta: order_with_respect_to = 'parent' - def __str__(self): - return self.title - class ModelWithNullFKToSite(models.Model): title = models.CharField(max_length=200) site = models.ForeignKey(Site, null=True, on_delete=models.CASCADE) post = models.ForeignKey(Post, null=True, on_delete=models.CASCADE) - def __str__(self): - return self.title - def get_absolute_url(self): return '/title/%s/' % quote(self.title) diff --git a/tests/custom_managers/models.py b/tests/custom_managers/models.py index ca2e14b047..14222bfaf3 100644 --- a/tests/custom_managers/models.py +++ b/tests/custom_managers/models.py @@ -130,9 +130,6 @@ class FunPerson(models.Model): objects = FunPeopleManager() - def __str__(self): - return "%s %s" % (self.first_name, self.last_name) - class Book(models.Model): title = models.CharField(max_length=50) @@ -157,9 +154,6 @@ class Book(models.Model): class Meta: base_manager_name = 'annotated_objects' - def __str__(self): - return self.title - class FastCarManager(models.Manager): def get_queryset(self): @@ -173,9 +167,6 @@ class Car(models.Model): cars = models.Manager() fast_cars = FastCarManager() - def __str__(self): - return self.name - class FastCarAsBase(Car): class Meta: @@ -197,9 +188,6 @@ class RestrictedManager(models.Manager): class RelatedModel(models.Model): name = models.CharField(max_length=50) - def __str__(self): - return self.name - class RestrictedModel(models.Model): name = models.CharField(max_length=50) @@ -209,9 +197,6 @@ class RestrictedModel(models.Model): objects = RestrictedManager() plain_manager = models.Manager() - def __str__(self): - return self.name - class OneToOneRestrictedModel(models.Model): name = models.CharField(max_length=50) @@ -221,9 +206,6 @@ class OneToOneRestrictedModel(models.Model): objects = RestrictedManager() plain_manager = models.Manager() - def __str__(self): - return self.name - class AbstractPerson(models.Model): abstract_persons = models.Manager() diff --git a/tests/custom_pk/models.py b/tests/custom_pk/models.py index 0b272c1135..edfc6712f3 100644 --- a/tests/custom_pk/models.py +++ b/tests/custom_pk/models.py @@ -29,16 +29,10 @@ class Business(models.Model): class Meta: verbose_name_plural = 'businesses' - def __str__(self): - return self.name - class Bar(models.Model): id = MyAutoField(primary_key=True, db_index=True) - def __str__(self): - return repr(self.pk) - class Foo(models.Model): bar = models.ForeignKey(Bar, models.CASCADE) diff --git a/tests/db_functions/models.py b/tests/db_functions/models.py index 0deea8f54c..97584326aa 100644 --- a/tests/db_functions/models.py +++ b/tests/db_functions/models.py @@ -10,9 +10,6 @@ class Author(models.Model): goes_by = models.CharField(max_length=50, null=True, blank=True) age = models.PositiveSmallIntegerField(default=30) - def __str__(self): - return self.name - class Article(models.Model): authors = models.ManyToManyField(Author, related_name='articles') @@ -24,9 +21,6 @@ class Article(models.Model): updated = models.DateTimeField(null=True, blank=True) views = models.PositiveIntegerField(default=0) - def __str__(self): - return self.title - class Fan(models.Model): name = models.CharField(max_length=50) @@ -34,9 +28,6 @@ class Fan(models.Model): author = models.ForeignKey(Author, models.CASCADE, related_name='fans') fan_since = models.DateTimeField(null=True, blank=True) - def __str__(self): - return self.name - class DTModel(models.Model): name = models.CharField(max_length=32) @@ -48,9 +39,6 @@ class DTModel(models.Model): end_time = models.TimeField(null=True, blank=True) duration = models.DurationField(null=True, blank=True) - def __str__(self): - return 'DTModel({})'.format(self.name) - class DecimalModel(models.Model): n1 = models.DecimalField(decimal_places=2, max_digits=6) diff --git a/tests/defer_regress/models.py b/tests/defer_regress/models.py index 8b05fc4130..78d4c3e646 100644 --- a/tests/defer_regress/models.py +++ b/tests/defer_regress/models.py @@ -11,9 +11,6 @@ class Item(models.Model): value = models.IntegerField() other_value = models.IntegerField(default=0) - def __str__(self): - return self.name - class RelatedItem(models.Model): item = models.ForeignKey(Item, models.CASCADE) @@ -35,9 +32,6 @@ class Leaf(models.Model): second_child = models.ForeignKey(Child, models.SET_NULL, related_name="other", null=True) value = models.IntegerField(default=42) - def __str__(self): - return self.name - class ResolveThis(models.Model): num = models.FloatField() @@ -53,9 +47,6 @@ class SimpleItem(models.Model): name = models.CharField(max_length=15) value = models.IntegerField() - def __str__(self): - return self.name - class Feature(models.Model): item = models.ForeignKey(SimpleItem, models.CASCADE) diff --git a/tests/delete/models.py b/tests/delete/models.py index 440581dc54..7f6e6a89ce 100644 --- a/tests/delete/models.py +++ b/tests/delete/models.py @@ -13,9 +13,6 @@ class R(models.Model): is_default = models.BooleanField(default=False) p = models.ForeignKey(P, models.CASCADE, null=True) - def __str__(self): - return "%s" % self.pk - def get_default_r(): return R.objects.get_or_create(is_default=True)[0].pk diff --git a/tests/expressions/models.py b/tests/expressions/models.py index a3129207fa..6e1ce37b10 100644 --- a/tests/expressions/models.py +++ b/tests/expressions/models.py @@ -100,6 +100,3 @@ class UUIDPK(models.Model): class UUID(models.Model): uuid = models.UUIDField(null=True) uuid_fk = models.ForeignKey(UUIDPK, models.CASCADE, null=True) - - def __str__(self): - return "%s" % self.uuid diff --git a/tests/expressions_case/models.py b/tests/expressions_case/models.py index d8a055ac38..8e8e33a678 100644 --- a/tests/expressions_case/models.py +++ b/tests/expressions_case/models.py @@ -38,25 +38,16 @@ class CaseTestModel(models.Model): uuid = models.UUIDField(null=True) fk = models.ForeignKey('self', models.CASCADE, null=True) - def __str__(self): - return "%i, %s" % (self.integer, self.string) - class O2OCaseTestModel(models.Model): o2o = models.OneToOneField(CaseTestModel, models.CASCADE, related_name='o2o_rel') integer = models.IntegerField() - def __str__(self): - return "%i, %s" % (self.id, self.o2o) - class FKCaseTestModel(models.Model): fk = models.ForeignKey(CaseTestModel, models.CASCADE, related_name='fk_rel') integer = models.IntegerField() - def __str__(self): - return "%i, %s" % (self.id, self.fk) - class Client(models.Model): REGULAR = 'R' @@ -74,6 +65,3 @@ class Client(models.Model): choices=ACCOUNT_TYPE_CHOICES, default=REGULAR, ) - - def __str__(self): - return self.name diff --git a/tests/expressions_window/models.py b/tests/expressions_window/models.py index d479d1aea6..ce6f6621e9 100644 --- a/tests/expressions_window/models.py +++ b/tests/expressions_window/models.py @@ -12,6 +12,3 @@ class Employee(models.Model): hire_date = models.DateField(blank=False, null=False) age = models.IntegerField(blank=False, null=False) classification = models.ForeignKey('Classification', on_delete=models.CASCADE, null=True) - - def __str__(self): - return '{}, {}, {}, {}'.format(self.name, self.department, self.salary, self.hire_date) diff --git a/tests/extra_regress/models.py b/tests/extra_regress/models.py index 3765601f7f..2847f8172b 100644 --- a/tests/extra_regress/models.py +++ b/tests/extra_regress/models.py @@ -10,9 +10,6 @@ class RevisionableModel(models.Model): title = models.CharField(blank=True, max_length=255) when = models.DateTimeField(default=datetime.datetime.now) - def __str__(self): - return "%s (%s, %s)" % (self.title, self.id, self.base.id) - def save(self, *args, force_insert=None, force_update=None, **kwargs): super().save(*args, force_insert=force_insert, force_update=force_update, **kwargs) if not self.base: diff --git a/tests/filtered_relation/models.py b/tests/filtered_relation/models.py index 501e731de7..60b3678d55 100644 --- a/tests/filtered_relation/models.py +++ b/tests/filtered_relation/models.py @@ -16,16 +16,10 @@ class Author(models.Model): object_id = models.PositiveIntegerField(null=True) content_object = GenericForeignKey() - def __str__(self): - return self.name - class Editor(models.Model): name = models.CharField(max_length=255) - def __str__(self): - return self.name - class Book(models.Model): AVAILABLE = 'available' @@ -47,16 +41,10 @@ class Book(models.Model): generic_author = GenericRelation(Author) state = models.CharField(max_length=9, choices=STATES, default=AVAILABLE) - def __str__(self): - return self.title - class Borrower(models.Model): name = models.CharField(max_length=50, unique=True) - def __str__(self): - return self.name - class Reservation(models.Model): NEW = 'new' @@ -79,9 +67,6 @@ class Reservation(models.Model): ) state = models.CharField(max_length=7, choices=STATES, default=NEW) - def __str__(self): - return '-'.join((self.book.name, self.borrower.name, self.state)) - class RentalSession(models.Model): NEW = 'new' @@ -103,6 +88,3 @@ class RentalSession(models.Model): related_query_name='rental_session', ) state = models.CharField(max_length=7, choices=STATES, default=NEW) - - def __str__(self): - return '-'.join((self.book.name, self.borrower.name, self.state)) diff --git a/tests/generic_relations_regress/models.py b/tests/generic_relations_regress/models.py index 4d5620b877..c598d9bfc8 100644 --- a/tests/generic_relations_regress/models.py +++ b/tests/generic_relations_regress/models.py @@ -14,9 +14,6 @@ class Link(models.Model): object_id = models.PositiveIntegerField() content_object = GenericForeignKey() - def __str__(self): - return "Link to %s id=%s" % (self.content_type, self.object_id) - class LinkProxy(Link): class Meta: @@ -28,18 +25,13 @@ class Place(models.Model): links = GenericRelation(Link, related_query_name='places') link_proxy = GenericRelation(LinkProxy) - def __str__(self): - return "Place: %s" % self.name - class Restaurant(Place): - def __str__(self): - return "Restaurant: %s" % self.name + pass class Cafe(Restaurant): - def __str__(self): - return "Cafe: %s" % self.name + pass class Address(models.Model): @@ -51,18 +43,12 @@ class Address(models.Model): object_id = models.PositiveIntegerField() content_object = GenericForeignKey() - def __str__(self): - return '%s %s, %s %s' % (self.street, self.city, self.state, self.zipcode) - class Person(models.Model): account = models.IntegerField(primary_key=True) name = models.CharField(max_length=128) addresses = GenericRelation(Address) - def __str__(self): - return self.name - class CharLink(models.Model): content_type = models.ForeignKey(ContentType, models.CASCADE) @@ -107,9 +93,6 @@ class Company(models.Model): name = models.CharField(max_length=100) links = GenericRelation(Link) - def __str__(self): - return "Company: %s" % self.name - # For testing #13085 fix, we also use Note model defined above class Developer(models.Model): @@ -120,9 +103,6 @@ class Team(models.Model): name = models.CharField(max_length=15) members = models.ManyToManyField(Developer) - def __str__(self): - return "%s team" % self.name - def __len__(self): return self.members.count() diff --git a/tests/get_or_create/models.py b/tests/get_or_create/models.py index 6510bb9464..f00d9c4d38 100644 --- a/tests/get_or_create/models.py +++ b/tests/get_or_create/models.py @@ -7,9 +7,6 @@ class Person(models.Model): birthday = models.DateField() defaults = models.TextField() - def __str__(self): - return '%s %s' % (self.first_name, self.last_name) - class DefaultPerson(models.Model): first_name = models.CharField(max_length=100, default="Anonymous") diff --git a/tests/lookup/models.py b/tests/lookup/models.py index 9fd3f14ed3..6a0afaacde 100644 --- a/tests/lookup/models.py +++ b/tests/lookup/models.py @@ -81,17 +81,11 @@ class Game(models.Model): home = models.CharField(max_length=100) away = models.CharField(max_length=100) - def __str__(self): - return "%s at %s" % (self.away, self.home) - class Player(models.Model): name = models.CharField(max_length=100) games = models.ManyToManyField(Game, related_name='players') - def __str__(self): - return self.name - class Product(models.Model): name = models.CharField(max_length=80) diff --git a/tests/m2m_intermediary/models.py b/tests/m2m_intermediary/models.py index 3101fd8a2d..1333d14b41 100644 --- a/tests/m2m_intermediary/models.py +++ b/tests/m2m_intermediary/models.py @@ -24,14 +24,8 @@ class Article(models.Model): headline = models.CharField(max_length=100) pub_date = models.DateField() - def __str__(self): - return self.headline - class Writer(models.Model): reporter = models.ForeignKey(Reporter, models.CASCADE) article = models.ForeignKey(Article, models.CASCADE) position = models.CharField(max_length=100) - - def __str__(self): - return '%s (%s)' % (self.reporter, self.position) diff --git a/tests/m2m_signals/models.py b/tests/m2m_signals/models.py index c156128c83..69809fe2d0 100644 --- a/tests/m2m_signals/models.py +++ b/tests/m2m_signals/models.py @@ -7,9 +7,6 @@ class Part(models.Model): class Meta: ordering = ('name',) - def __str__(self): - return self.name - class Car(models.Model): name = models.CharField(max_length=20) @@ -19,9 +16,6 @@ class Car(models.Model): class Meta: ordering = ('name',) - def __str__(self): - return self.name - class SportsCar(Car): price = models.IntegerField() @@ -34,6 +28,3 @@ class Person(models.Model): class Meta: ordering = ('name',) - - def __str__(self): - return self.name diff --git a/tests/m2m_through/models.py b/tests/m2m_through/models.py index 53d04a05f3..2cc0bd6848 100644 --- a/tests/m2m_through/models.py +++ b/tests/m2m_through/models.py @@ -10,9 +10,6 @@ class Person(models.Model): class Meta: ordering = ('name',) - def __str__(self): - return self.name - class Group(models.Model): name = models.CharField(max_length=128) @@ -27,9 +24,6 @@ class Group(models.Model): class Meta: ordering = ('name',) - def __str__(self): - return self.name - class Membership(models.Model): person = models.ForeignKey(Person, models.CASCADE) @@ -74,9 +68,6 @@ class PersonSelfRefM2M(models.Model): friends = models.ManyToManyField('self', through="Friendship", symmetrical=False) sym_friends = models.ManyToManyField('self', through='SymmetricalFriendship', symmetrical=True) - def __str__(self): - return self.name - class Friendship(models.Model): first = models.ForeignKey(PersonSelfRefM2M, models.CASCADE, related_name="rel_from_set") @@ -99,9 +90,6 @@ class Event(models.Model): related_name='events_invited', ) - def __str__(self): - return self.title - class Invitation(models.Model): event = models.ForeignKey(Event, models.CASCADE, related_name='invitations') @@ -122,9 +110,6 @@ class Employee(models.Model): class Meta: ordering = ('pk',) - def __str__(self): - return self.name - class Relationship(models.Model): # field order is deliberately inverted. diff --git a/tests/m2m_through_regress/models.py b/tests/m2m_through_regress/models.py index 5405e5595c..7d64e7cf75 100644 --- a/tests/m2m_through_regress/models.py +++ b/tests/m2m_through_regress/models.py @@ -8,9 +8,6 @@ class Membership(models.Model): group = models.ForeignKey('Group', models.CASCADE) price = models.IntegerField(default=100) - def __str__(self): - return "%s is a member of %s" % (self.person.name, self.group.name) - # using custom id column to test ticket #11107 class UserMembership(models.Model): @@ -19,9 +16,6 @@ class UserMembership(models.Model): group = models.ForeignKey('Group', models.CASCADE) price = models.IntegerField(default=100) - def __str__(self): - return "%s is a user and member of %s" % (self.user.username, self.group.name) - class Person(models.Model): name = models.CharField(max_length=128) diff --git a/tests/many_to_one/models.py b/tests/many_to_one/models.py index 6e00fb18fa..e9f8fbff76 100644 --- a/tests/many_to_one/models.py +++ b/tests/many_to_one/models.py @@ -37,9 +37,6 @@ class City(models.Model): country = models.ForeignKey(Country, models.CASCADE, related_name='cities', null=True) name = models.CharField(max_length=50) - def __str__(self): - return self.name - class District(models.Model): city = models.ForeignKey(City, models.CASCADE, related_name='districts', null=True) diff --git a/tests/many_to_one_null/models.py b/tests/many_to_one_null/models.py index 23b4294593..d8561fcee5 100644 --- a/tests/many_to_one_null/models.py +++ b/tests/many_to_one_null/models.py @@ -11,9 +11,6 @@ from django.db import models class Reporter(models.Model): name = models.CharField(max_length=30) - def __str__(self): - return self.name - class Article(models.Model): headline = models.CharField(max_length=100) diff --git a/tests/model_inheritance/models.py b/tests/model_inheritance/models.py index 58c076d536..fa37e121ea 100644 --- a/tests/model_inheritance/models.py +++ b/tests/model_inheritance/models.py @@ -61,9 +61,6 @@ class Attachment(models.Model): class Meta: abstract = True - def __str__(self): - return self.content - class Comment(Attachment): is_spam = models.BooleanField(default=False) @@ -80,17 +77,11 @@ class Link(Attachment): class Chef(models.Model): name = models.CharField(max_length=50) - def __str__(self): - return "%s the chef" % self.name - class Place(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=80) - def __str__(self): - return "%s the place" % self.name - class Rating(models.Model): rating = models.IntegerField(null=True, blank=True) @@ -108,32 +99,20 @@ class Restaurant(Place, Rating): class Meta(Rating.Meta): db_table = 'my_restaurant' - def __str__(self): - return "%s the restaurant" % self.name - class ItalianRestaurant(Restaurant): serves_gnocchi = models.BooleanField(default=False) - def __str__(self): - return "%s the italian restaurant" % self.name - class Supplier(Place): customers = models.ManyToManyField(Restaurant, related_name='provider') - def __str__(self): - return "%s the supplier" % self.name - class ParkingLot(Place): # An explicit link to the parent (we can control the attribute name). parent = models.OneToOneField(Place, models.CASCADE, primary_key=True, parent_link=True) main_site = models.ForeignKey(Place, models.CASCADE, related_name='lot') - def __str__(self): - return "%s the parking lot" % self.name - # # Abstract base classes with related models where the sub-class has the diff --git a/tests/model_inheritance_regress/models.py b/tests/model_inheritance_regress/models.py index 5e4c928dc9..1f5f516aac 100644 --- a/tests/model_inheritance_regress/models.py +++ b/tests/model_inheritance_regress/models.py @@ -10,33 +10,21 @@ class Place(models.Model): class Meta: ordering = ('name',) - def __str__(self): - return "%s the place" % self.name - class Restaurant(Place): serves_hot_dogs = models.BooleanField(default=False) serves_pizza = models.BooleanField(default=False) - def __str__(self): - return "%s the restaurant" % self.name - class ItalianRestaurant(Restaurant): serves_gnocchi = models.BooleanField(default=False) - def __str__(self): - return "%s the italian restaurant" % self.name - class ParkingLot(Place): # An explicit link to the parent (we can control the attribute name). parent = models.OneToOneField(Place, models.CASCADE, primary_key=True, parent_link=True) capacity = models.IntegerField() - def __str__(self): - return "%s the parking lot" % self.name - class ParkingLot3(Place): # The parent_link connector need not be the pk on the model. @@ -64,9 +52,6 @@ class Supplier(models.Model): name = models.CharField(max_length=50) restaurant = models.ForeignKey(Restaurant, models.CASCADE) - def __str__(self): - return self.name - class Wholesaler(Supplier): retailer = models.ForeignKey(Supplier, models.CASCADE, related_name='wholesale_supplier') @@ -96,9 +81,6 @@ class Article(models.Model): class Meta: ordering = ('-pub_date', 'headline') - def __str__(self): - return self.headline - class ArticleWithAuthor(Article): author = models.CharField(max_length=100) @@ -126,18 +108,11 @@ class QualityControl(Evaluation): class BaseM(models.Model): base_name = models.CharField(max_length=100) - def __str__(self): - return self.base_name - class DerivedM(BaseM): customPK = models.IntegerField(primary_key=True) derived_name = models.CharField(max_length=100) - def __str__(self): - return "PK = %d, base_name = %s, derived_name = %s" % ( - self.customPK, self.base_name, self.derived_name) - class AuditBase(models.Model): planned_date = models.DateField() @@ -163,9 +138,6 @@ class Person(models.Model): class Meta: ordering = ('name',) - def __str__(self): - return self.name - class AbstractEvent(models.Model): name = models.CharField(max_length=100) @@ -175,9 +147,6 @@ class AbstractEvent(models.Model): abstract = True ordering = ('name',) - def __str__(self): - return self.name - class BirthdayParty(AbstractEvent): pass diff --git a/tests/model_regress/models.py b/tests/model_regress/models.py index a9786e37ab..b55ed96097 100644 --- a/tests/model_regress/models.py +++ b/tests/model_regress/models.py @@ -17,9 +17,6 @@ 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 __str__(self): - return self.headline - class Movie(models.Model): # Test models with non-default primary keys / AutoFields #5218 @@ -39,9 +36,6 @@ class Department(models.Model): id = models.PositiveIntegerField(primary_key=True) name = models.CharField(max_length=200) - def __str__(self): - return self.name - class Worker(models.Model): department = models.ForeignKey(Department, models.CASCADE) diff --git a/tests/multiple_database/models.py b/tests/multiple_database/models.py index ace89fac89..e4e764d6a5 100644 --- a/tests/multiple_database/models.py +++ b/tests/multiple_database/models.py @@ -72,9 +72,6 @@ class Pet(models.Model): class Meta: ordering = ('name',) - def __str__(self): - return self.name - class UserProfile(models.Model): user = models.OneToOneField(User, models.SET_NULL, null=True) diff --git a/tests/null_fk_ordering/models.py b/tests/null_fk_ordering/models.py index 82f3fed9f9..f42ff7b8d5 100644 --- a/tests/null_fk_ordering/models.py +++ b/tests/null_fk_ordering/models.py @@ -20,9 +20,6 @@ class Article(models.Model): class Meta: ordering = ['author__name'] - def __str__(self): - return 'Article titled: %s' % self.title - # These following 4 models represent a far more complex ordering case. class SystemInfo(models.Model): @@ -38,9 +35,6 @@ class Post(models.Model): forum = models.ForeignKey(Forum, models.SET_NULL, null=True) title = models.CharField(max_length=32) - def __str__(self): - return self.title - class Comment(models.Model): post = models.ForeignKey(Post, models.SET_NULL, null=True) @@ -48,6 +42,3 @@ class Comment(models.Model): class Meta: ordering = ['post__forum__system_info__system_name', 'comment_text'] - - def __str__(self): - return self.comment_text diff --git a/tests/null_queries/models.py b/tests/null_queries/models.py index f2d4caa745..298d4d9277 100644 --- a/tests/null_queries/models.py +++ b/tests/null_queries/models.py @@ -4,17 +4,11 @@ from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) - def __str__(self): - return "Q: %s " % self.question - class Choice(models.Model): poll = models.ForeignKey(Poll, models.CASCADE) choice = models.CharField(max_length=200) - 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/one_to_one/models.py b/tests/one_to_one/models.py index 5e8b918f25..827dd89afa 100644 --- a/tests/one_to_one/models.py +++ b/tests/one_to_one/models.py @@ -29,9 +29,6 @@ class Bar(models.Model): place = models.OneToOneField(Place, models.CASCADE) serves_cocktails = models.BooleanField(default=True) - def __str__(self): - return "%s the bar" % self.place.name - class UndergroundBar(models.Model): place = models.OneToOneField(Place, models.SET_NULL, null=True) @@ -50,9 +47,6 @@ class Favorites(models.Model): name = models.CharField(max_length=50) restaurants = models.ManyToManyField(Restaurant) - def __str__(self): - return "Favorites for %s" % self.name - class ManualPrimaryKey(models.Model): primary_key = models.CharField(max_length=10, primary_key=True) diff --git a/tests/ordering/models.py b/tests/ordering/models.py index f5a237fe45..2efb743e44 100644 --- a/tests/ordering/models.py +++ b/tests/ordering/models.py @@ -37,9 +37,6 @@ class Article(models.Model): models.OrderBy(models.F('second_author__name')), ) - def __str__(self): - return self.headline - class OrderedByAuthorArticle(Article): class Meta: diff --git a/tests/prefetch_related/models.py b/tests/prefetch_related/models.py index a3c0237d8e..0ded7e8b4a 100644 --- a/tests/prefetch_related/models.py +++ b/tests/prefetch_related/models.py @@ -42,9 +42,6 @@ class AuthorAddress(models.Model): class Meta: ordering = ['id'] - def __str__(self): - return self.address - class Book(models.Model): title = models.CharField(max_length=255) @@ -53,9 +50,6 @@ class Book(models.Model): class Meta: ordering = ['id'] - def __str__(self): - return self.title - class BookWithYear(Book): book = models.OneToOneField(Book, models.CASCADE, parent_link=True) @@ -168,9 +162,6 @@ class TaggedItem(models.Model): class Meta: ordering = ['id'] - def __str__(self): - return self.tag - class Article(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) @@ -254,9 +245,6 @@ class Employee(models.Model): class Meta: ordering = ['id'] - def __str__(self): - return self.name - # Ticket #19607 @@ -264,17 +252,11 @@ class LessonEntry(models.Model): name1 = models.CharField(max_length=200) name2 = models.CharField(max_length=200) - def __str__(self): - return "%s %s" % (self.name1, self.name2) - class WordEntry(models.Model): lesson_entry = models.ForeignKey(LessonEntry, models.CASCADE) name = models.CharField(max_length=200) - def __str__(self): - return "%s (%s)" % (self.name, self.id) - # Ticket #21410: Regression when related_name="+" @@ -286,9 +268,6 @@ class Author2(models.Model): class Meta: ordering = ['id'] - def __str__(self): - return self.name - # Models for many-to-many with UUID pk test: diff --git a/tests/reverse_lookup/models.py b/tests/reverse_lookup/models.py index e7db427255..97c1cd289a 100644 --- a/tests/reverse_lookup/models.py +++ b/tests/reverse_lookup/models.py @@ -10,22 +10,13 @@ from django.db import models class User(models.Model): name = models.CharField(max_length=200) - def __str__(self): - return self.name - class Poll(models.Model): question = models.CharField(max_length=200) creator = models.ForeignKey(User, models.CASCADE) - def __str__(self): - return self.question - class Choice(models.Model): name = models.CharField(max_length=100) poll = models.ForeignKey(Poll, models.CASCADE, related_name="poll_choice") related_poll = models.ForeignKey(Poll, models.CASCADE, related_name="related_choice") - - def __str__(self): - return self.name diff --git a/tests/select_related/models.py b/tests/select_related/models.py index b3f113efa8..7cb083fc20 100644 --- a/tests/select_related/models.py +++ b/tests/select_related/models.py @@ -19,65 +19,41 @@ from django.db import models class Domain(models.Model): name = models.CharField(max_length=50) - def __str__(self): - return self.name - class Kingdom(models.Model): name = models.CharField(max_length=50) domain = models.ForeignKey(Domain, models.CASCADE) - def __str__(self): - return self.name - class Phylum(models.Model): name = models.CharField(max_length=50) kingdom = models.ForeignKey(Kingdom, models.CASCADE) - def __str__(self): - return self.name - class Klass(models.Model): name = models.CharField(max_length=50) phylum = models.ForeignKey(Phylum, models.CASCADE) - def __str__(self): - return self.name - class Order(models.Model): name = models.CharField(max_length=50) klass = models.ForeignKey(Klass, models.CASCADE) - def __str__(self): - return self.name - class Family(models.Model): name = models.CharField(max_length=50) order = models.ForeignKey(Order, models.CASCADE) - def __str__(self): - return self.name - class Genus(models.Model): name = models.CharField(max_length=50) family = models.ForeignKey(Family, models.CASCADE) - def __str__(self): - return self.name - class Species(models.Model): name = models.CharField(max_length=50) genus = models.ForeignKey(Genus, models.CASCADE) - def __str__(self): - return self.name - # and we'll invent a new thing so we have a model with two foreign keys @@ -86,24 +62,15 @@ class HybridSpecies(models.Model): parent_1 = models.ForeignKey(Species, models.CASCADE, related_name='child_1') parent_2 = models.ForeignKey(Species, models.CASCADE, related_name='child_2') - def __str__(self): - return self.name - class Topping(models.Model): name = models.CharField(max_length=30) - def __str__(self): - return self.name - class Pizza(models.Model): name = models.CharField(max_length=100) toppings = models.ManyToManyField(Topping) - def __str__(self): - return self.name - class TaggedItem(models.Model): tag = models.CharField(max_length=30) @@ -112,13 +79,7 @@ class TaggedItem(models.Model): object_id = models.PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') - def __str__(self): - return self.tag - class Bookmark(models.Model): url = models.URLField() tags = GenericRelation(TaggedItem) - - def __str__(self): - return self.url diff --git a/tests/select_related_onetoone/models.py b/tests/select_related_onetoone/models.py index a1852f421e..aefa3518a9 100644 --- a/tests/select_related_onetoone/models.py +++ b/tests/select_related_onetoone/models.py @@ -5,42 +5,27 @@ class User(models.Model): username = models.CharField(max_length=100) email = models.EmailField() - def __str__(self): - return self.username - class UserProfile(models.Model): user = models.OneToOneField(User, models.CASCADE) city = models.CharField(max_length=100) state = models.CharField(max_length=2) - def __str__(self): - return "%s, %s" % (self.city, self.state) - class UserStatResult(models.Model): results = models.CharField(max_length=50) - def __str__(self): - return 'UserStatResults, results = %s' % self.results - class UserStat(models.Model): user = models.OneToOneField(User, models.CASCADE, primary_key=True) posts = models.IntegerField() results = models.ForeignKey(UserStatResult, models.CASCADE) - def __str__(self): - return 'UserStat, posts = %s' % self.posts - class StatDetails(models.Model): base_stats = models.OneToOneField(UserStat, models.CASCADE) comments = models.IntegerField() - def __str__(self): - return 'StatDetails, comments = %s' % self.comments - class AdvancedUserStat(UserStat): karma = models.IntegerField() @@ -58,33 +43,21 @@ class Product(models.Model): class Parent1(models.Model): name1 = models.CharField(max_length=50) - def __str__(self): - return self.name1 - class Parent2(models.Model): # Avoid having two "id" fields in the Child1 subclass id2 = models.AutoField(primary_key=True) name2 = models.CharField(max_length=50) - def __str__(self): - return self.name2 - class Child1(Parent1, Parent2): value = models.IntegerField() - def __str__(self): - return self.name1 - class Child2(Parent1): parent2 = models.OneToOneField(Parent2, models.CASCADE) value = models.IntegerField() - def __str__(self): - return self.name1 - class Child3(Child2): value3 = models.IntegerField() diff --git a/tests/select_related_regress/models.py b/tests/select_related_regress/models.py index ed4d98544b..83e9321ef7 100644 --- a/tests/select_related_regress/models.py +++ b/tests/select_related_regress/models.py @@ -4,17 +4,11 @@ from django.db import models class Building(models.Model): name = models.CharField(max_length=10) - def __str__(self): - return "Building: %s" % self.name - class Device(models.Model): building = models.ForeignKey('Building', models.CASCADE) name = models.CharField(max_length=10) - def __str__(self): - return "device '%s' in building %s" % (self.name, self.building) - class Port(models.Model): device = models.ForeignKey('Device', models.CASCADE) @@ -38,9 +32,6 @@ class Connection(models.Model): unique=True, ) - def __str__(self): - return "%s to %s" % (self.start, self.end) - # Another non-tree hierarchy that exercises code paths similar to the above # example, but in a slightly different configuration. @@ -100,9 +91,6 @@ class SpecialClient(Client): class Parent(models.Model): name = models.CharField(max_length=10) - def __str__(self): - return self.name - class Child(Parent): value = models.IntegerField() @@ -121,9 +109,6 @@ class Item(models.Model): class Fowl(models.Model): name = models.CharField(max_length=10) - def __str__(self): - return self.name - class Hen(Fowl): pass