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()
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):

View File

@ -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()

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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))

View File

@ -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()

View File

@ -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")

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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.

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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.

View File

@ -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)

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -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