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