2014-01-22 06:43:33 +00:00
|
|
|
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
|
2010-03-15 13:15:01 +00:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2011-10-13 18:51:33 +00:00
|
|
|
from django.db import models
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-03-15 13:15:01 +00:00
|
|
|
class Award(models.Model):
|
|
|
|
name = models.CharField(max_length=25)
|
|
|
|
object_id = models.PositiveIntegerField()
|
2015-07-22 14:43:21 +00:00
|
|
|
content_type = models.ForeignKey(ContentType, models.CASCADE)
|
2014-01-22 06:43:33 +00:00
|
|
|
content_object = GenericForeignKey()
|
2010-03-15 13:15:01 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-03-15 13:15:01 +00:00
|
|
|
class AwardNote(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
award = models.ForeignKey(Award, models.CASCADE)
|
2010-03-15 13:15:01 +00:00
|
|
|
note = models.CharField(max_length=100)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-03-15 13:15:01 +00:00
|
|
|
class Person(models.Model):
|
|
|
|
name = models.CharField(max_length=25)
|
2014-01-22 06:43:33 +00:00
|
|
|
awards = GenericRelation(Award)
|
2009-06-03 13:23:19 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-06-03 13:23:19 +00:00
|
|
|
class Book(models.Model):
|
|
|
|
pagecount = models.IntegerField()
|
2021-04-27 07:53:27 +00:00
|
|
|
owner = models.ForeignKey("Child", models.CASCADE, null=True)
|
2009-06-03 13:23:19 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-03-15 13:15:01 +00:00
|
|
|
class Toy(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-03-15 13:15:01 +00:00
|
|
|
class Child(models.Model):
|
|
|
|
name = models.CharField(max_length=50)
|
|
|
|
toys = models.ManyToManyField(Toy, through="PlayedWith")
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-03-15 13:15:01 +00:00
|
|
|
class PlayedWith(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
child = models.ForeignKey(Child, models.CASCADE)
|
|
|
|
toy = models.ForeignKey(Toy, models.CASCADE)
|
2010-04-04 17:42:23 +00:00
|
|
|
date = models.DateField(db_column="date_col")
|
2010-03-15 13:15:01 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2010-03-15 13:15:01 +00:00
|
|
|
class PlayedWithNote(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
played = models.ForeignKey(PlayedWith, models.CASCADE)
|
2010-03-15 13:15:01 +00:00
|
|
|
note = models.TextField()
|
2011-01-19 21:56:14 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-01-19 21:56:14 +00:00
|
|
|
class Contact(models.Model):
|
|
|
|
label = models.CharField(max_length=100)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-01-19 21:56:14 +00:00
|
|
|
class Email(Contact):
|
|
|
|
email_address = models.EmailField(max_length=100)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-01-19 21:56:14 +00:00
|
|
|
class Researcher(models.Model):
|
|
|
|
contacts = models.ManyToManyField(Contact, related_name="research_contacts")
|
2018-01-13 11:23:48 +00:00
|
|
|
primary_contact = models.ForeignKey(
|
|
|
|
Contact, models.SET_NULL, null=True, related_name="primary_contacts"
|
|
|
|
)
|
|
|
|
secondary_contact = models.ForeignKey(
|
|
|
|
Contact, models.SET_NULL, null=True, related_name="secondary_contacts"
|
|
|
|
)
|
2011-01-25 03:14:28 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-01-25 03:14:28 +00:00
|
|
|
class Food(models.Model):
|
|
|
|
name = models.CharField(max_length=20, unique=True)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-01-25 03:14:28 +00:00
|
|
|
class Eaten(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
food = models.ForeignKey(Food, models.CASCADE, to_field="name")
|
2011-01-25 03:14:28 +00:00
|
|
|
meal = models.CharField(max_length=20)
|
2011-05-30 16:04:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Models for #15776
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-05-30 16:04:25 +00:00
|
|
|
class Policy(models.Model):
|
|
|
|
policy_number = models.CharField(max_length=10)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-05-30 16:04:25 +00:00
|
|
|
class Version(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
policy = models.ForeignKey(Policy, models.CASCADE)
|
2011-05-30 16:04:25 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-05-30 16:04:25 +00:00
|
|
|
class Location(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
version = models.ForeignKey(Version, models.SET_NULL, blank=True, null=True)
|
2011-05-30 16:04:25 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-05-30 16:04:25 +00:00
|
|
|
class Item(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
version = models.ForeignKey(Version, models.CASCADE)
|
|
|
|
location = models.ForeignKey(Location, models.SET_NULL, blank=True, null=True)
|
2022-08-17 20:33:22 +00:00
|
|
|
location_value = models.ForeignKey(
|
|
|
|
Location, models.SET(42), default=1, db_constraint=False, related_name="+"
|
|
|
|
)
|
2012-03-05 03:41:01 +00:00
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
|
2012-03-05 03:41:01 +00:00
|
|
|
# Models for #16128
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-03-05 03:41:01 +00:00
|
|
|
class File(models.Model):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-03-05 03:41:01 +00:00
|
|
|
class Image(File):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-03-05 03:41:01 +00:00
|
|
|
class Photo(Image):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-03-05 03:41:01 +00:00
|
|
|
class FooImage(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
my_image = models.ForeignKey(Image, models.CASCADE)
|
2012-03-05 03:41:01 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-03-05 03:41:01 +00:00
|
|
|
class FooFile(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
my_file = models.ForeignKey(File, models.CASCADE)
|
2012-03-05 03:41:01 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-03-05 03:41:01 +00:00
|
|
|
class FooPhoto(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
my_photo = models.ForeignKey(Photo, models.CASCADE)
|
2012-03-05 03:41:01 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-03-17 01:24:39 +00:00
|
|
|
class FooFileProxy(FooFile):
|
|
|
|
class Meta:
|
|
|
|
proxy = True
|
2012-10-10 12:58:39 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-10-10 12:58:39 +00:00
|
|
|
class OrgUnit(models.Model):
|
|
|
|
name = models.CharField(max_length=64, unique=True)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-10-10 12:58:39 +00:00
|
|
|
class Login(models.Model):
|
|
|
|
description = models.CharField(max_length=32)
|
2015-07-22 14:43:21 +00:00
|
|
|
orgunit = models.ForeignKey(OrgUnit, models.CASCADE)
|
2013-02-10 17:49:28 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2013-02-10 17:49:28 +00:00
|
|
|
class House(models.Model):
|
|
|
|
address = models.CharField(max_length=32)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2013-02-10 17:49:28 +00:00
|
|
|
class OrderedPerson(models.Model):
|
|
|
|
name = models.CharField(max_length=32)
|
2015-07-22 14:43:21 +00:00
|
|
|
lives_in = models.ForeignKey(House, models.CASCADE)
|
2013-02-10 17:49:28 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ["name"]
|
2024-02-08 17:41:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_best_toy():
|
|
|
|
toy, _ = Toy.objects.get_or_create(name="best")
|
|
|
|
return toy
|
|
|
|
|
|
|
|
|
|
|
|
def get_worst_toy():
|
|
|
|
toy, _ = Toy.objects.get_or_create(name="worst")
|
|
|
|
return toy
|
|
|
|
|
|
|
|
|
|
|
|
class Collector(models.Model):
|
|
|
|
best_toy = models.ForeignKey(
|
|
|
|
Toy, default=get_best_toy, on_delete=models.SET_DEFAULT, related_name="toys"
|
|
|
|
)
|
|
|
|
worst_toy = models.ForeignKey(
|
|
|
|
Toy, models.SET(get_worst_toy), related_name="bad_toys"
|
|
|
|
)
|