2018-05-03 21:41:04 +08:00
|
|
|
import uuid
|
|
|
|
|
2009-05-14 23:09:33 +08:00
|
|
|
from django.db import models
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-04-29 17:51:12 +08:00
|
|
|
class Event(models.Model):
|
2012-07-15 17:24:21 +08:00
|
|
|
# Oracle can have problems with a column named "date"
|
|
|
|
date = models.DateField(db_column="event_date")
|
2011-10-14 02:51:33 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2009-05-14 23:09:33 +08:00
|
|
|
class Parent(models.Model):
|
|
|
|
name = models.CharField(max_length=128)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2009-05-14 23:09:33 +08:00
|
|
|
class Child(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey(Parent, models.SET_NULL, editable=False, null=True)
|
2011-01-24 15:01:00 +08:00
|
|
|
name = models.CharField(max_length=30, blank=True)
|
2011-10-26 20:19:18 +08:00
|
|
|
age = models.IntegerField(null=True, blank=True)
|
2011-02-14 06:51:40 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class Genre(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class Band(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
nr_of_members = models.PositiveIntegerField()
|
|
|
|
genres = models.ManyToManyField(Genre)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class Musician(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
2017-07-05 19:00:10 +08:00
|
|
|
age = models.IntegerField(null=True, blank=True)
|
2011-02-14 06:51:40 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-02-14 06:51:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class Group(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
members = models.ManyToManyField(Musician, through="Membership")
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2011-02-14 06:51:40 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2015-04-14 17:09:58 +08:00
|
|
|
class Concert(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
2015-07-22 22:43:21 +08:00
|
|
|
group = models.ForeignKey(Group, models.CASCADE)
|
2015-04-14 17:09:58 +08:00
|
|
|
|
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class Membership(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
music = models.ForeignKey(Musician, models.CASCADE)
|
|
|
|
group = models.ForeignKey(Group, models.CASCADE)
|
2011-02-14 06:51:40 +08:00
|
|
|
role = models.CharField(max_length=15)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class Quartet(Group):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class ChordsMusician(Musician):
|
|
|
|
pass
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class ChordsBand(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
members = models.ManyToManyField(ChordsMusician, through="Invitation")
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class Invitation(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
player = models.ForeignKey(ChordsMusician, models.CASCADE)
|
|
|
|
band = models.ForeignKey(ChordsBand, models.CASCADE)
|
2011-02-14 06:51:40 +08:00
|
|
|
instrument = models.CharField(max_length=15)
|
2011-11-18 05:30:07 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-11-18 05:30:07 +08:00
|
|
|
class Swallow(models.Model):
|
2018-05-03 21:41:04 +08:00
|
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
2011-11-18 05:30:07 +08:00
|
|
|
origin = models.CharField(max_length=255)
|
|
|
|
load = models.FloatField()
|
|
|
|
speed = models.FloatField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ("speed", "load")
|
2012-03-03 10:13:35 +08:00
|
|
|
|
|
|
|
|
2015-05-27 23:43:22 +08:00
|
|
|
class SwallowOneToOne(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
swallow = models.OneToOneField(Swallow, models.CASCADE)
|
2015-05-27 23:43:22 +08:00
|
|
|
|
|
|
|
|
2012-03-03 10:13:35 +08:00
|
|
|
class UnorderedObject(models.Model):
|
|
|
|
"""
|
|
|
|
Model without any defined `Meta.ordering`.
|
|
|
|
Refs #17198.
|
|
|
|
"""
|
2022-02-04 03:24:19 +08:00
|
|
|
|
2012-03-03 10:13:35 +08:00
|
|
|
bool = models.BooleanField(default=True)
|
|
|
|
|
|
|
|
|
|
|
|
class OrderedObjectManager(models.Manager):
|
2013-03-08 22:15:23 +08:00
|
|
|
def get_queryset(self):
|
2017-01-21 21:13:44 +08:00
|
|
|
return super().get_queryset().order_by("number")
|
2012-03-03 10:13:35 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-03-03 10:13:35 +08:00
|
|
|
class OrderedObject(models.Model):
|
|
|
|
"""
|
|
|
|
Model with Manager that defines a default order.
|
|
|
|
Refs #17198.
|
|
|
|
"""
|
2022-02-04 03:24:19 +08:00
|
|
|
|
2012-03-03 10:13:35 +08:00
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
bool = models.BooleanField(default=True)
|
2012-03-19 20:52:15 +08:00
|
|
|
number = models.IntegerField(default=0, db_column="number_val")
|
2012-03-03 10:13:35 +08:00
|
|
|
|
2012-03-19 20:52:15 +08:00
|
|
|
objects = OrderedObjectManager()
|
2013-03-20 06:17:31 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2013-03-20 06:17:31 +08:00
|
|
|
class CustomIdUser(models.Model):
|
|
|
|
uuid = models.AutoField(primary_key=True)
|
2017-07-05 19:00:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
class CharPK(models.Model):
|
|
|
|
char_pk = models.CharField(max_length=100, primary_key=True)
|