Removed unused __str__() methods in tests models.

Follow up to 6461583b6c.
This commit is contained in:
Mariusz Felisiak 2020-04-30 09:13:23 +02:00 committed by GitHub
parent bb13711451
commit 555e3a848e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 2 additions and 400 deletions

View File

@ -10,17 +10,11 @@ class Author(models.Model):
age = models.IntegerField() age = models.IntegerField()
friends = models.ManyToManyField('self', blank=True) friends = models.ManyToManyField('self', blank=True)
def __str__(self):
return self.name
class Publisher(models.Model): class Publisher(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
num_awards = models.IntegerField() num_awards = models.IntegerField()
def __str__(self):
return self.name
class ItemTag(models.Model): class ItemTag(models.Model):
tag = models.CharField(max_length=100) tag = models.CharField(max_length=100)
@ -44,9 +38,6 @@ class Book(models.Model):
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
def __str__(self):
return self.name
class Store(models.Model): class Store(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
@ -54,9 +45,6 @@ class Store(models.Model):
original_opening = models.DateTimeField() original_opening = models.DateTimeField()
friday_night_closing = models.TimeField() friday_night_closing = models.TimeField()
def __str__(self):
return self.name
class Entries(models.Model): class Entries(models.Model):
EntryID = models.AutoField(primary_key=True, db_column='Entry ID') EntryID = models.AutoField(primary_key=True, db_column='Entry ID')
@ -81,9 +69,6 @@ class WithManualPK(models.Model):
class HardbackBook(Book): class HardbackBook(Book):
weight = models.FloatField() weight = models.FloatField()
def __str__(self):
return "%s (hardback): %s" % (self.name, self.weight)
# Models for ticket #21150 # Models for ticket #21150
class Alfa(models.Model): class Alfa(models.Model):

View File

@ -54,11 +54,6 @@ class Company(models.Model):
ticker_name = models.CharField(max_length=10, null=True, blank=True) ticker_name = models.CharField(max_length=10, null=True, blank=True)
description = models.CharField(max_length=200, 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): class Ticket(models.Model):
active_at = models.DateTimeField() active_at = models.DateTimeField()

View File

@ -12,16 +12,10 @@ class Site(models.Model):
domain = models.CharField(max_length=100) domain = models.CharField(max_length=100)
objects = SiteManager() objects = SiteManager()
def __str__(self):
return self.domain
class Author(models.Model): class Author(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
def __str__(self):
return self.name
def get_absolute_url(self): def get_absolute_url(self):
return '/authors/%s/' % self.id return '/authors/%s/' % self.id
@ -32,16 +26,10 @@ class Article(models.Model):
author = models.ForeignKey(Author, models.CASCADE) author = models.ForeignKey(Author, models.CASCADE)
date_created = models.DateTimeField() date_created = models.DateTimeField()
def __str__(self):
return self.title
class SchemeIncludedURL(models.Model): class SchemeIncludedURL(models.Model):
url = models.URLField(max_length=100) url = models.URLField(max_length=100)
def __str__(self):
return self.url
def get_absolute_url(self): def get_absolute_url(self):
return self.url return self.url
@ -62,9 +50,6 @@ class FooWithoutUrl(models.Model):
""" """
name = models.CharField(max_length=30, unique=True) name = models.CharField(max_length=30, unique=True)
def __str__(self):
return self.name
class FooWithUrl(FooWithoutUrl): class FooWithUrl(FooWithoutUrl):
""" """
@ -99,9 +84,6 @@ class Answer(models.Model):
class Meta: class Meta:
order_with_respect_to = 'question' order_with_respect_to = 'question'
def __str__(self):
return self.text
class Post(models.Model): class Post(models.Model):
"""An ordered tag on an item.""" """An ordered tag on an item."""
@ -114,18 +96,12 @@ class Post(models.Model):
class Meta: class Meta:
order_with_respect_to = 'parent' order_with_respect_to = 'parent'
def __str__(self):
return self.title
class ModelWithNullFKToSite(models.Model): class ModelWithNullFKToSite(models.Model):
title = models.CharField(max_length=200) title = models.CharField(max_length=200)
site = models.ForeignKey(Site, null=True, on_delete=models.CASCADE) site = models.ForeignKey(Site, null=True, on_delete=models.CASCADE)
post = models.ForeignKey(Post, 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): def get_absolute_url(self):
return '/title/%s/' % quote(self.title) return '/title/%s/' % quote(self.title)

View File

@ -130,9 +130,6 @@ class FunPerson(models.Model):
objects = FunPeopleManager() objects = FunPeopleManager()
def __str__(self):
return "%s %s" % (self.first_name, self.last_name)
class Book(models.Model): class Book(models.Model):
title = models.CharField(max_length=50) title = models.CharField(max_length=50)
@ -157,9 +154,6 @@ class Book(models.Model):
class Meta: class Meta:
base_manager_name = 'annotated_objects' base_manager_name = 'annotated_objects'
def __str__(self):
return self.title
class FastCarManager(models.Manager): class FastCarManager(models.Manager):
def get_queryset(self): def get_queryset(self):
@ -173,9 +167,6 @@ class Car(models.Model):
cars = models.Manager() cars = models.Manager()
fast_cars = FastCarManager() fast_cars = FastCarManager()
def __str__(self):
return self.name
class FastCarAsBase(Car): class FastCarAsBase(Car):
class Meta: class Meta:
@ -197,9 +188,6 @@ class RestrictedManager(models.Manager):
class RelatedModel(models.Model): class RelatedModel(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
def __str__(self):
return self.name
class RestrictedModel(models.Model): class RestrictedModel(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
@ -209,9 +197,6 @@ class RestrictedModel(models.Model):
objects = RestrictedManager() objects = RestrictedManager()
plain_manager = models.Manager() plain_manager = models.Manager()
def __str__(self):
return self.name
class OneToOneRestrictedModel(models.Model): class OneToOneRestrictedModel(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
@ -221,9 +206,6 @@ class OneToOneRestrictedModel(models.Model):
objects = RestrictedManager() objects = RestrictedManager()
plain_manager = models.Manager() plain_manager = models.Manager()
def __str__(self):
return self.name
class AbstractPerson(models.Model): class AbstractPerson(models.Model):
abstract_persons = models.Manager() abstract_persons = models.Manager()

View File

@ -29,16 +29,10 @@ class Business(models.Model):
class Meta: class Meta:
verbose_name_plural = 'businesses' verbose_name_plural = 'businesses'
def __str__(self):
return self.name
class Bar(models.Model): class Bar(models.Model):
id = MyAutoField(primary_key=True, db_index=True) id = MyAutoField(primary_key=True, db_index=True)
def __str__(self):
return repr(self.pk)
class Foo(models.Model): class Foo(models.Model):
bar = models.ForeignKey(Bar, models.CASCADE) bar = models.ForeignKey(Bar, models.CASCADE)

View File

@ -10,9 +10,6 @@ class Author(models.Model):
goes_by = models.CharField(max_length=50, null=True, blank=True) goes_by = models.CharField(max_length=50, null=True, blank=True)
age = models.PositiveSmallIntegerField(default=30) age = models.PositiveSmallIntegerField(default=30)
def __str__(self):
return self.name
class Article(models.Model): class Article(models.Model):
authors = models.ManyToManyField(Author, related_name='articles') authors = models.ManyToManyField(Author, related_name='articles')
@ -24,9 +21,6 @@ class Article(models.Model):
updated = models.DateTimeField(null=True, blank=True) updated = models.DateTimeField(null=True, blank=True)
views = models.PositiveIntegerField(default=0) views = models.PositiveIntegerField(default=0)
def __str__(self):
return self.title
class Fan(models.Model): class Fan(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
@ -34,9 +28,6 @@ class Fan(models.Model):
author = models.ForeignKey(Author, models.CASCADE, related_name='fans') author = models.ForeignKey(Author, models.CASCADE, related_name='fans')
fan_since = models.DateTimeField(null=True, blank=True) fan_since = models.DateTimeField(null=True, blank=True)
def __str__(self):
return self.name
class DTModel(models.Model): class DTModel(models.Model):
name = models.CharField(max_length=32) name = models.CharField(max_length=32)
@ -48,9 +39,6 @@ class DTModel(models.Model):
end_time = models.TimeField(null=True, blank=True) end_time = models.TimeField(null=True, blank=True)
duration = models.DurationField(null=True, blank=True) duration = models.DurationField(null=True, blank=True)
def __str__(self):
return 'DTModel({})'.format(self.name)
class DecimalModel(models.Model): class DecimalModel(models.Model):
n1 = models.DecimalField(decimal_places=2, max_digits=6) n1 = models.DecimalField(decimal_places=2, max_digits=6)

View File

@ -11,9 +11,6 @@ class Item(models.Model):
value = models.IntegerField() value = models.IntegerField()
other_value = models.IntegerField(default=0) other_value = models.IntegerField(default=0)
def __str__(self):
return self.name
class RelatedItem(models.Model): class RelatedItem(models.Model):
item = models.ForeignKey(Item, models.CASCADE) 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) second_child = models.ForeignKey(Child, models.SET_NULL, related_name="other", null=True)
value = models.IntegerField(default=42) value = models.IntegerField(default=42)
def __str__(self):
return self.name
class ResolveThis(models.Model): class ResolveThis(models.Model):
num = models.FloatField() num = models.FloatField()
@ -53,9 +47,6 @@ class SimpleItem(models.Model):
name = models.CharField(max_length=15) name = models.CharField(max_length=15)
value = models.IntegerField() value = models.IntegerField()
def __str__(self):
return self.name
class Feature(models.Model): class Feature(models.Model):
item = models.ForeignKey(SimpleItem, models.CASCADE) item = models.ForeignKey(SimpleItem, models.CASCADE)

View File

@ -13,9 +13,6 @@ class R(models.Model):
is_default = models.BooleanField(default=False) is_default = models.BooleanField(default=False)
p = models.ForeignKey(P, models.CASCADE, null=True) p = models.ForeignKey(P, models.CASCADE, null=True)
def __str__(self):
return "%s" % self.pk
def get_default_r(): def get_default_r():
return R.objects.get_or_create(is_default=True)[0].pk return R.objects.get_or_create(is_default=True)[0].pk

View File

@ -100,6 +100,3 @@ class UUIDPK(models.Model):
class UUID(models.Model): class UUID(models.Model):
uuid = models.UUIDField(null=True) uuid = models.UUIDField(null=True)
uuid_fk = models.ForeignKey(UUIDPK, models.CASCADE, null=True) uuid_fk = models.ForeignKey(UUIDPK, models.CASCADE, null=True)
def __str__(self):
return "%s" % self.uuid

View File

@ -38,25 +38,16 @@ class CaseTestModel(models.Model):
uuid = models.UUIDField(null=True) uuid = models.UUIDField(null=True)
fk = models.ForeignKey('self', models.CASCADE, null=True) fk = models.ForeignKey('self', models.CASCADE, null=True)
def __str__(self):
return "%i, %s" % (self.integer, self.string)
class O2OCaseTestModel(models.Model): class O2OCaseTestModel(models.Model):
o2o = models.OneToOneField(CaseTestModel, models.CASCADE, related_name='o2o_rel') o2o = models.OneToOneField(CaseTestModel, models.CASCADE, related_name='o2o_rel')
integer = models.IntegerField() integer = models.IntegerField()
def __str__(self):
return "%i, %s" % (self.id, self.o2o)
class FKCaseTestModel(models.Model): class FKCaseTestModel(models.Model):
fk = models.ForeignKey(CaseTestModel, models.CASCADE, related_name='fk_rel') fk = models.ForeignKey(CaseTestModel, models.CASCADE, related_name='fk_rel')
integer = models.IntegerField() integer = models.IntegerField()
def __str__(self):
return "%i, %s" % (self.id, self.fk)
class Client(models.Model): class Client(models.Model):
REGULAR = 'R' REGULAR = 'R'
@ -74,6 +65,3 @@ class Client(models.Model):
choices=ACCOUNT_TYPE_CHOICES, choices=ACCOUNT_TYPE_CHOICES,
default=REGULAR, default=REGULAR,
) )
def __str__(self):
return self.name

View File

@ -12,6 +12,3 @@ class Employee(models.Model):
hire_date = models.DateField(blank=False, null=False) hire_date = models.DateField(blank=False, null=False)
age = models.IntegerField(blank=False, null=False) age = models.IntegerField(blank=False, null=False)
classification = models.ForeignKey('Classification', on_delete=models.CASCADE, null=True) classification = models.ForeignKey('Classification', on_delete=models.CASCADE, null=True)
def __str__(self):
return '{}, {}, {}, {}'.format(self.name, self.department, self.salary, self.hire_date)

View File

@ -10,9 +10,6 @@ class RevisionableModel(models.Model):
title = models.CharField(blank=True, max_length=255) title = models.CharField(blank=True, max_length=255)
when = models.DateTimeField(default=datetime.datetime.now) 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): def save(self, *args, force_insert=None, force_update=None, **kwargs):
super().save(*args, force_insert=force_insert, force_update=force_update, **kwargs) super().save(*args, force_insert=force_insert, force_update=force_update, **kwargs)
if not self.base: if not self.base:

View File

@ -16,16 +16,10 @@ class Author(models.Model):
object_id = models.PositiveIntegerField(null=True) object_id = models.PositiveIntegerField(null=True)
content_object = GenericForeignKey() content_object = GenericForeignKey()
def __str__(self):
return self.name
class Editor(models.Model): class Editor(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
def __str__(self):
return self.name
class Book(models.Model): class Book(models.Model):
AVAILABLE = 'available' AVAILABLE = 'available'
@ -47,16 +41,10 @@ class Book(models.Model):
generic_author = GenericRelation(Author) generic_author = GenericRelation(Author)
state = models.CharField(max_length=9, choices=STATES, default=AVAILABLE) state = models.CharField(max_length=9, choices=STATES, default=AVAILABLE)
def __str__(self):
return self.title
class Borrower(models.Model): class Borrower(models.Model):
name = models.CharField(max_length=50, unique=True) name = models.CharField(max_length=50, unique=True)
def __str__(self):
return self.name
class Reservation(models.Model): class Reservation(models.Model):
NEW = 'new' NEW = 'new'
@ -79,9 +67,6 @@ class Reservation(models.Model):
) )
state = models.CharField(max_length=7, choices=STATES, default=NEW) 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): class RentalSession(models.Model):
NEW = 'new' NEW = 'new'
@ -103,6 +88,3 @@ class RentalSession(models.Model):
related_query_name='rental_session', related_query_name='rental_session',
) )
state = models.CharField(max_length=7, choices=STATES, default=NEW) state = models.CharField(max_length=7, choices=STATES, default=NEW)
def __str__(self):
return '-'.join((self.book.name, self.borrower.name, self.state))

View File

@ -14,9 +14,6 @@ class Link(models.Model):
object_id = models.PositiveIntegerField() object_id = models.PositiveIntegerField()
content_object = GenericForeignKey() content_object = GenericForeignKey()
def __str__(self):
return "Link to %s id=%s" % (self.content_type, self.object_id)
class LinkProxy(Link): class LinkProxy(Link):
class Meta: class Meta:
@ -28,18 +25,13 @@ class Place(models.Model):
links = GenericRelation(Link, related_query_name='places') links = GenericRelation(Link, related_query_name='places')
link_proxy = GenericRelation(LinkProxy) link_proxy = GenericRelation(LinkProxy)
def __str__(self):
return "Place: %s" % self.name
class Restaurant(Place): class Restaurant(Place):
def __str__(self): pass
return "Restaurant: %s" % self.name
class Cafe(Restaurant): class Cafe(Restaurant):
def __str__(self): pass
return "Cafe: %s" % self.name
class Address(models.Model): class Address(models.Model):
@ -51,18 +43,12 @@ class Address(models.Model):
object_id = models.PositiveIntegerField() object_id = models.PositiveIntegerField()
content_object = GenericForeignKey() content_object = GenericForeignKey()
def __str__(self):
return '%s %s, %s %s' % (self.street, self.city, self.state, self.zipcode)
class Person(models.Model): class Person(models.Model):
account = models.IntegerField(primary_key=True) account = models.IntegerField(primary_key=True)
name = models.CharField(max_length=128) name = models.CharField(max_length=128)
addresses = GenericRelation(Address) addresses = GenericRelation(Address)
def __str__(self):
return self.name
class CharLink(models.Model): class CharLink(models.Model):
content_type = models.ForeignKey(ContentType, models.CASCADE) content_type = models.ForeignKey(ContentType, models.CASCADE)
@ -107,9 +93,6 @@ class Company(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
links = GenericRelation(Link) links = GenericRelation(Link)
def __str__(self):
return "Company: %s" % self.name
# For testing #13085 fix, we also use Note model defined above # For testing #13085 fix, we also use Note model defined above
class Developer(models.Model): class Developer(models.Model):
@ -120,9 +103,6 @@ class Team(models.Model):
name = models.CharField(max_length=15) name = models.CharField(max_length=15)
members = models.ManyToManyField(Developer) members = models.ManyToManyField(Developer)
def __str__(self):
return "%s team" % self.name
def __len__(self): def __len__(self):
return self.members.count() return self.members.count()

View File

@ -7,9 +7,6 @@ class Person(models.Model):
birthday = models.DateField() birthday = models.DateField()
defaults = models.TextField() defaults = models.TextField()
def __str__(self):
return '%s %s' % (self.first_name, self.last_name)
class DefaultPerson(models.Model): class DefaultPerson(models.Model):
first_name = models.CharField(max_length=100, default="Anonymous") first_name = models.CharField(max_length=100, default="Anonymous")

View File

@ -81,17 +81,11 @@ class Game(models.Model):
home = models.CharField(max_length=100) home = models.CharField(max_length=100)
away = 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): class Player(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
games = models.ManyToManyField(Game, related_name='players') games = models.ManyToManyField(Game, related_name='players')
def __str__(self):
return self.name
class Product(models.Model): class Product(models.Model):
name = models.CharField(max_length=80) name = models.CharField(max_length=80)

View File

@ -24,14 +24,8 @@ class Article(models.Model):
headline = models.CharField(max_length=100) headline = models.CharField(max_length=100)
pub_date = models.DateField() pub_date = models.DateField()
def __str__(self):
return self.headline
class Writer(models.Model): class Writer(models.Model):
reporter = models.ForeignKey(Reporter, models.CASCADE) reporter = models.ForeignKey(Reporter, models.CASCADE)
article = models.ForeignKey(Article, models.CASCADE) article = models.ForeignKey(Article, models.CASCADE)
position = models.CharField(max_length=100) position = models.CharField(max_length=100)
def __str__(self):
return '%s (%s)' % (self.reporter, self.position)

View File

@ -7,9 +7,6 @@ class Part(models.Model):
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
def __str__(self):
return self.name
class Car(models.Model): class Car(models.Model):
name = models.CharField(max_length=20) name = models.CharField(max_length=20)
@ -19,9 +16,6 @@ class Car(models.Model):
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
def __str__(self):
return self.name
class SportsCar(Car): class SportsCar(Car):
price = models.IntegerField() price = models.IntegerField()
@ -34,6 +28,3 @@ class Person(models.Model):
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
def __str__(self):
return self.name

View File

@ -10,9 +10,6 @@ class Person(models.Model):
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
def __str__(self):
return self.name
class Group(models.Model): class Group(models.Model):
name = models.CharField(max_length=128) name = models.CharField(max_length=128)
@ -27,9 +24,6 @@ class Group(models.Model):
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
def __str__(self):
return self.name
class Membership(models.Model): class Membership(models.Model):
person = models.ForeignKey(Person, models.CASCADE) person = models.ForeignKey(Person, models.CASCADE)
@ -74,9 +68,6 @@ class PersonSelfRefM2M(models.Model):
friends = models.ManyToManyField('self', through="Friendship", symmetrical=False) friends = models.ManyToManyField('self', through="Friendship", symmetrical=False)
sym_friends = models.ManyToManyField('self', through='SymmetricalFriendship', symmetrical=True) sym_friends = models.ManyToManyField('self', through='SymmetricalFriendship', symmetrical=True)
def __str__(self):
return self.name
class Friendship(models.Model): class Friendship(models.Model):
first = models.ForeignKey(PersonSelfRefM2M, models.CASCADE, related_name="rel_from_set") first = models.ForeignKey(PersonSelfRefM2M, models.CASCADE, related_name="rel_from_set")
@ -99,9 +90,6 @@ class Event(models.Model):
related_name='events_invited', related_name='events_invited',
) )
def __str__(self):
return self.title
class Invitation(models.Model): class Invitation(models.Model):
event = models.ForeignKey(Event, models.CASCADE, related_name='invitations') event = models.ForeignKey(Event, models.CASCADE, related_name='invitations')
@ -122,9 +110,6 @@ class Employee(models.Model):
class Meta: class Meta:
ordering = ('pk',) ordering = ('pk',)
def __str__(self):
return self.name
class Relationship(models.Model): class Relationship(models.Model):
# field order is deliberately inverted. # field order is deliberately inverted.

View File

@ -8,9 +8,6 @@ class Membership(models.Model):
group = models.ForeignKey('Group', models.CASCADE) group = models.ForeignKey('Group', models.CASCADE)
price = models.IntegerField(default=100) 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 # using custom id column to test ticket #11107
class UserMembership(models.Model): class UserMembership(models.Model):
@ -19,9 +16,6 @@ class UserMembership(models.Model):
group = models.ForeignKey('Group', models.CASCADE) group = models.ForeignKey('Group', models.CASCADE)
price = models.IntegerField(default=100) 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): class Person(models.Model):
name = models.CharField(max_length=128) name = models.CharField(max_length=128)

View File

@ -37,9 +37,6 @@ class City(models.Model):
country = models.ForeignKey(Country, models.CASCADE, related_name='cities', null=True) country = models.ForeignKey(Country, models.CASCADE, related_name='cities', null=True)
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
def __str__(self):
return self.name
class District(models.Model): class District(models.Model):
city = models.ForeignKey(City, models.CASCADE, related_name='districts', null=True) city = models.ForeignKey(City, models.CASCADE, related_name='districts', null=True)

View File

@ -11,9 +11,6 @@ from django.db import models
class Reporter(models.Model): class Reporter(models.Model):
name = models.CharField(max_length=30) name = models.CharField(max_length=30)
def __str__(self):
return self.name
class Article(models.Model): class Article(models.Model):
headline = models.CharField(max_length=100) headline = models.CharField(max_length=100)

View File

@ -61,9 +61,6 @@ class Attachment(models.Model):
class Meta: class Meta:
abstract = True abstract = True
def __str__(self):
return self.content
class Comment(Attachment): class Comment(Attachment):
is_spam = models.BooleanField(default=False) is_spam = models.BooleanField(default=False)
@ -80,17 +77,11 @@ class Link(Attachment):
class Chef(models.Model): class Chef(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
def __str__(self):
return "%s the chef" % self.name
class Place(models.Model): class Place(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
address = models.CharField(max_length=80) address = models.CharField(max_length=80)
def __str__(self):
return "%s the place" % self.name
class Rating(models.Model): class Rating(models.Model):
rating = models.IntegerField(null=True, blank=True) rating = models.IntegerField(null=True, blank=True)
@ -108,32 +99,20 @@ class Restaurant(Place, Rating):
class Meta(Rating.Meta): class Meta(Rating.Meta):
db_table = 'my_restaurant' db_table = 'my_restaurant'
def __str__(self):
return "%s the restaurant" % self.name
class ItalianRestaurant(Restaurant): class ItalianRestaurant(Restaurant):
serves_gnocchi = models.BooleanField(default=False) serves_gnocchi = models.BooleanField(default=False)
def __str__(self):
return "%s the italian restaurant" % self.name
class Supplier(Place): class Supplier(Place):
customers = models.ManyToManyField(Restaurant, related_name='provider') customers = models.ManyToManyField(Restaurant, related_name='provider')
def __str__(self):
return "%s the supplier" % self.name
class ParkingLot(Place): class ParkingLot(Place):
# An explicit link to the parent (we can control the attribute name). # An explicit link to the parent (we can control the attribute name).
parent = models.OneToOneField(Place, models.CASCADE, primary_key=True, parent_link=True) parent = models.OneToOneField(Place, models.CASCADE, primary_key=True, parent_link=True)
main_site = models.ForeignKey(Place, models.CASCADE, related_name='lot') 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 # Abstract base classes with related models where the sub-class has the

View File

@ -10,33 +10,21 @@ class Place(models.Model):
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
def __str__(self):
return "%s the place" % self.name
class Restaurant(Place): class Restaurant(Place):
serves_hot_dogs = models.BooleanField(default=False) serves_hot_dogs = models.BooleanField(default=False)
serves_pizza = models.BooleanField(default=False) serves_pizza = models.BooleanField(default=False)
def __str__(self):
return "%s the restaurant" % self.name
class ItalianRestaurant(Restaurant): class ItalianRestaurant(Restaurant):
serves_gnocchi = models.BooleanField(default=False) serves_gnocchi = models.BooleanField(default=False)
def __str__(self):
return "%s the italian restaurant" % self.name
class ParkingLot(Place): class ParkingLot(Place):
# An explicit link to the parent (we can control the attribute name). # An explicit link to the parent (we can control the attribute name).
parent = models.OneToOneField(Place, models.CASCADE, primary_key=True, parent_link=True) parent = models.OneToOneField(Place, models.CASCADE, primary_key=True, parent_link=True)
capacity = models.IntegerField() capacity = models.IntegerField()
def __str__(self):
return "%s the parking lot" % self.name
class ParkingLot3(Place): class ParkingLot3(Place):
# The parent_link connector need not be the pk on the model. # 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) name = models.CharField(max_length=50)
restaurant = models.ForeignKey(Restaurant, models.CASCADE) restaurant = models.ForeignKey(Restaurant, models.CASCADE)
def __str__(self):
return self.name
class Wholesaler(Supplier): class Wholesaler(Supplier):
retailer = models.ForeignKey(Supplier, models.CASCADE, related_name='wholesale_supplier') retailer = models.ForeignKey(Supplier, models.CASCADE, related_name='wholesale_supplier')
@ -96,9 +81,6 @@ class Article(models.Model):
class Meta: class Meta:
ordering = ('-pub_date', 'headline') ordering = ('-pub_date', 'headline')
def __str__(self):
return self.headline
class ArticleWithAuthor(Article): class ArticleWithAuthor(Article):
author = models.CharField(max_length=100) author = models.CharField(max_length=100)
@ -126,18 +108,11 @@ class QualityControl(Evaluation):
class BaseM(models.Model): class BaseM(models.Model):
base_name = models.CharField(max_length=100) base_name = models.CharField(max_length=100)
def __str__(self):
return self.base_name
class DerivedM(BaseM): class DerivedM(BaseM):
customPK = models.IntegerField(primary_key=True) customPK = models.IntegerField(primary_key=True)
derived_name = models.CharField(max_length=100) 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): class AuditBase(models.Model):
planned_date = models.DateField() planned_date = models.DateField()
@ -163,9 +138,6 @@ class Person(models.Model):
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
def __str__(self):
return self.name
class AbstractEvent(models.Model): class AbstractEvent(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
@ -175,9 +147,6 @@ class AbstractEvent(models.Model):
abstract = True abstract = True
ordering = ('name',) ordering = ('name',)
def __str__(self):
return self.name
class BirthdayParty(AbstractEvent): class BirthdayParty(AbstractEvent):
pass pass

View File

@ -17,9 +17,6 @@ class Article(models.Model):
# A utf-8 verbose name (Ångström's Articles) to test they are valid. # A utf-8 verbose name (Ångström's Articles) to test they are valid.
verbose_name = "\xc3\x85ngstr\xc3\xb6m's Articles" verbose_name = "\xc3\x85ngstr\xc3\xb6m's Articles"
def __str__(self):
return self.headline
class Movie(models.Model): class Movie(models.Model):
# Test models with non-default primary keys / AutoFields #5218 # Test models with non-default primary keys / AutoFields #5218
@ -39,9 +36,6 @@ class Department(models.Model):
id = models.PositiveIntegerField(primary_key=True) id = models.PositiveIntegerField(primary_key=True)
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
def __str__(self):
return self.name
class Worker(models.Model): class Worker(models.Model):
department = models.ForeignKey(Department, models.CASCADE) department = models.ForeignKey(Department, models.CASCADE)

View File

@ -72,9 +72,6 @@ class Pet(models.Model):
class Meta: class Meta:
ordering = ('name',) ordering = ('name',)
def __str__(self):
return self.name
class UserProfile(models.Model): class UserProfile(models.Model):
user = models.OneToOneField(User, models.SET_NULL, null=True) user = models.OneToOneField(User, models.SET_NULL, null=True)

View File

@ -20,9 +20,6 @@ class Article(models.Model):
class Meta: class Meta:
ordering = ['author__name'] ordering = ['author__name']
def __str__(self):
return 'Article titled: %s' % self.title
# These following 4 models represent a far more complex ordering case. # These following 4 models represent a far more complex ordering case.
class SystemInfo(models.Model): class SystemInfo(models.Model):
@ -38,9 +35,6 @@ class Post(models.Model):
forum = models.ForeignKey(Forum, models.SET_NULL, null=True) forum = models.ForeignKey(Forum, models.SET_NULL, null=True)
title = models.CharField(max_length=32) title = models.CharField(max_length=32)
def __str__(self):
return self.title
class Comment(models.Model): class Comment(models.Model):
post = models.ForeignKey(Post, models.SET_NULL, null=True) post = models.ForeignKey(Post, models.SET_NULL, null=True)
@ -48,6 +42,3 @@ class Comment(models.Model):
class Meta: class Meta:
ordering = ['post__forum__system_info__system_name', 'comment_text'] ordering = ['post__forum__system_info__system_name', 'comment_text']
def __str__(self):
return self.comment_text

View File

@ -4,17 +4,11 @@ from django.db import models
class Poll(models.Model): class Poll(models.Model):
question = models.CharField(max_length=200) question = models.CharField(max_length=200)
def __str__(self):
return "Q: %s " % self.question
class Choice(models.Model): class Choice(models.Model):
poll = models.ForeignKey(Poll, models.CASCADE) poll = models.ForeignKey(Poll, models.CASCADE)
choice = models.CharField(max_length=200) 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. # A set of models with an inner one pointing to two outer ones.

View File

@ -29,9 +29,6 @@ class Bar(models.Model):
place = models.OneToOneField(Place, models.CASCADE) place = models.OneToOneField(Place, models.CASCADE)
serves_cocktails = models.BooleanField(default=True) serves_cocktails = models.BooleanField(default=True)
def __str__(self):
return "%s the bar" % self.place.name
class UndergroundBar(models.Model): class UndergroundBar(models.Model):
place = models.OneToOneField(Place, models.SET_NULL, null=True) place = models.OneToOneField(Place, models.SET_NULL, null=True)
@ -50,9 +47,6 @@ class Favorites(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
restaurants = models.ManyToManyField(Restaurant) restaurants = models.ManyToManyField(Restaurant)
def __str__(self):
return "Favorites for %s" % self.name
class ManualPrimaryKey(models.Model): class ManualPrimaryKey(models.Model):
primary_key = models.CharField(max_length=10, primary_key=True) primary_key = models.CharField(max_length=10, primary_key=True)

View File

@ -37,9 +37,6 @@ class Article(models.Model):
models.OrderBy(models.F('second_author__name')), models.OrderBy(models.F('second_author__name')),
) )
def __str__(self):
return self.headline
class OrderedByAuthorArticle(Article): class OrderedByAuthorArticle(Article):
class Meta: class Meta:

View File

@ -42,9 +42,6 @@ class AuthorAddress(models.Model):
class Meta: class Meta:
ordering = ['id'] ordering = ['id']
def __str__(self):
return self.address
class Book(models.Model): class Book(models.Model):
title = models.CharField(max_length=255) title = models.CharField(max_length=255)
@ -53,9 +50,6 @@ class Book(models.Model):
class Meta: class Meta:
ordering = ['id'] ordering = ['id']
def __str__(self):
return self.title
class BookWithYear(Book): class BookWithYear(Book):
book = models.OneToOneField(Book, models.CASCADE, parent_link=True) book = models.OneToOneField(Book, models.CASCADE, parent_link=True)
@ -168,9 +162,6 @@ class TaggedItem(models.Model):
class Meta: class Meta:
ordering = ['id'] ordering = ['id']
def __str__(self):
return self.tag
class Article(models.Model): class Article(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
@ -254,9 +245,6 @@ class Employee(models.Model):
class Meta: class Meta:
ordering = ['id'] ordering = ['id']
def __str__(self):
return self.name
# Ticket #19607 # Ticket #19607
@ -264,17 +252,11 @@ class LessonEntry(models.Model):
name1 = models.CharField(max_length=200) name1 = models.CharField(max_length=200)
name2 = 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): class WordEntry(models.Model):
lesson_entry = models.ForeignKey(LessonEntry, models.CASCADE) lesson_entry = models.ForeignKey(LessonEntry, models.CASCADE)
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
def __str__(self):
return "%s (%s)" % (self.name, self.id)
# Ticket #21410: Regression when related_name="+" # Ticket #21410: Regression when related_name="+"
@ -286,9 +268,6 @@ class Author2(models.Model):
class Meta: class Meta:
ordering = ['id'] ordering = ['id']
def __str__(self):
return self.name
# Models for many-to-many with UUID pk test: # Models for many-to-many with UUID pk test:

View File

@ -10,22 +10,13 @@ from django.db import models
class User(models.Model): class User(models.Model):
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
def __str__(self):
return self.name
class Poll(models.Model): class Poll(models.Model):
question = models.CharField(max_length=200) question = models.CharField(max_length=200)
creator = models.ForeignKey(User, models.CASCADE) creator = models.ForeignKey(User, models.CASCADE)
def __str__(self):
return self.question
class Choice(models.Model): class Choice(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
poll = models.ForeignKey(Poll, models.CASCADE, related_name="poll_choice") poll = models.ForeignKey(Poll, models.CASCADE, related_name="poll_choice")
related_poll = models.ForeignKey(Poll, models.CASCADE, related_name="related_choice") related_poll = models.ForeignKey(Poll, models.CASCADE, related_name="related_choice")
def __str__(self):
return self.name

View File

@ -19,65 +19,41 @@ from django.db import models
class Domain(models.Model): class Domain(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
def __str__(self):
return self.name
class Kingdom(models.Model): class Kingdom(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
domain = models.ForeignKey(Domain, models.CASCADE) domain = models.ForeignKey(Domain, models.CASCADE)
def __str__(self):
return self.name
class Phylum(models.Model): class Phylum(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
kingdom = models.ForeignKey(Kingdom, models.CASCADE) kingdom = models.ForeignKey(Kingdom, models.CASCADE)
def __str__(self):
return self.name
class Klass(models.Model): class Klass(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
phylum = models.ForeignKey(Phylum, models.CASCADE) phylum = models.ForeignKey(Phylum, models.CASCADE)
def __str__(self):
return self.name
class Order(models.Model): class Order(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
klass = models.ForeignKey(Klass, models.CASCADE) klass = models.ForeignKey(Klass, models.CASCADE)
def __str__(self):
return self.name
class Family(models.Model): class Family(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
order = models.ForeignKey(Order, models.CASCADE) order = models.ForeignKey(Order, models.CASCADE)
def __str__(self):
return self.name
class Genus(models.Model): class Genus(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
family = models.ForeignKey(Family, models.CASCADE) family = models.ForeignKey(Family, models.CASCADE)
def __str__(self):
return self.name
class Species(models.Model): class Species(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
genus = models.ForeignKey(Genus, models.CASCADE) 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 # 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_1 = models.ForeignKey(Species, models.CASCADE, related_name='child_1')
parent_2 = models.ForeignKey(Species, models.CASCADE, related_name='child_2') parent_2 = models.ForeignKey(Species, models.CASCADE, related_name='child_2')
def __str__(self):
return self.name
class Topping(models.Model): class Topping(models.Model):
name = models.CharField(max_length=30) name = models.CharField(max_length=30)
def __str__(self):
return self.name
class Pizza(models.Model): class Pizza(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
toppings = models.ManyToManyField(Topping) toppings = models.ManyToManyField(Topping)
def __str__(self):
return self.name
class TaggedItem(models.Model): class TaggedItem(models.Model):
tag = models.CharField(max_length=30) tag = models.CharField(max_length=30)
@ -112,13 +79,7 @@ class TaggedItem(models.Model):
object_id = models.PositiveIntegerField() object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id') content_object = GenericForeignKey('content_type', 'object_id')
def __str__(self):
return self.tag
class Bookmark(models.Model): class Bookmark(models.Model):
url = models.URLField() url = models.URLField()
tags = GenericRelation(TaggedItem) tags = GenericRelation(TaggedItem)
def __str__(self):
return self.url

View File

@ -5,42 +5,27 @@ class User(models.Model):
username = models.CharField(max_length=100) username = models.CharField(max_length=100)
email = models.EmailField() email = models.EmailField()
def __str__(self):
return self.username
class UserProfile(models.Model): class UserProfile(models.Model):
user = models.OneToOneField(User, models.CASCADE) user = models.OneToOneField(User, models.CASCADE)
city = models.CharField(max_length=100) city = models.CharField(max_length=100)
state = models.CharField(max_length=2) state = models.CharField(max_length=2)
def __str__(self):
return "%s, %s" % (self.city, self.state)
class UserStatResult(models.Model): class UserStatResult(models.Model):
results = models.CharField(max_length=50) results = models.CharField(max_length=50)
def __str__(self):
return 'UserStatResults, results = %s' % self.results
class UserStat(models.Model): class UserStat(models.Model):
user = models.OneToOneField(User, models.CASCADE, primary_key=True) user = models.OneToOneField(User, models.CASCADE, primary_key=True)
posts = models.IntegerField() posts = models.IntegerField()
results = models.ForeignKey(UserStatResult, models.CASCADE) results = models.ForeignKey(UserStatResult, models.CASCADE)
def __str__(self):
return 'UserStat, posts = %s' % self.posts
class StatDetails(models.Model): class StatDetails(models.Model):
base_stats = models.OneToOneField(UserStat, models.CASCADE) base_stats = models.OneToOneField(UserStat, models.CASCADE)
comments = models.IntegerField() comments = models.IntegerField()
def __str__(self):
return 'StatDetails, comments = %s' % self.comments
class AdvancedUserStat(UserStat): class AdvancedUserStat(UserStat):
karma = models.IntegerField() karma = models.IntegerField()
@ -58,33 +43,21 @@ class Product(models.Model):
class Parent1(models.Model): class Parent1(models.Model):
name1 = models.CharField(max_length=50) name1 = models.CharField(max_length=50)
def __str__(self):
return self.name1
class Parent2(models.Model): class Parent2(models.Model):
# Avoid having two "id" fields in the Child1 subclass # Avoid having two "id" fields in the Child1 subclass
id2 = models.AutoField(primary_key=True) id2 = models.AutoField(primary_key=True)
name2 = models.CharField(max_length=50) name2 = models.CharField(max_length=50)
def __str__(self):
return self.name2
class Child1(Parent1, Parent2): class Child1(Parent1, Parent2):
value = models.IntegerField() value = models.IntegerField()
def __str__(self):
return self.name1
class Child2(Parent1): class Child2(Parent1):
parent2 = models.OneToOneField(Parent2, models.CASCADE) parent2 = models.OneToOneField(Parent2, models.CASCADE)
value = models.IntegerField() value = models.IntegerField()
def __str__(self):
return self.name1
class Child3(Child2): class Child3(Child2):
value3 = models.IntegerField() value3 = models.IntegerField()

View File

@ -4,17 +4,11 @@ from django.db import models
class Building(models.Model): class Building(models.Model):
name = models.CharField(max_length=10) name = models.CharField(max_length=10)
def __str__(self):
return "Building: %s" % self.name
class Device(models.Model): class Device(models.Model):
building = models.ForeignKey('Building', models.CASCADE) building = models.ForeignKey('Building', models.CASCADE)
name = models.CharField(max_length=10) name = models.CharField(max_length=10)
def __str__(self):
return "device '%s' in building %s" % (self.name, self.building)
class Port(models.Model): class Port(models.Model):
device = models.ForeignKey('Device', models.CASCADE) device = models.ForeignKey('Device', models.CASCADE)
@ -38,9 +32,6 @@ class Connection(models.Model):
unique=True, 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 # Another non-tree hierarchy that exercises code paths similar to the above
# example, but in a slightly different configuration. # example, but in a slightly different configuration.
@ -100,9 +91,6 @@ class SpecialClient(Client):
class Parent(models.Model): class Parent(models.Model):
name = models.CharField(max_length=10) name = models.CharField(max_length=10)
def __str__(self):
return self.name
class Child(Parent): class Child(Parent):
value = models.IntegerField() value = models.IntegerField()
@ -121,9 +109,6 @@ class Item(models.Model):
class Fowl(models.Model): class Fowl(models.Model):
name = models.CharField(max_length=10) name = models.CharField(max_length=10)
def __str__(self):
return self.name
class Hen(Fowl): class Hen(Fowl):
pass pass