2009-05-14 23:09:33 +08:00
|
|
|
from django.db import models
|
2012-08-12 18:32:08 +08:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2009-05-14 23:09:33 +08:00
|
|
|
|
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):
|
2011-01-24 15:01:00 +08:00
|
|
|
parent = models.ForeignKey(Parent, editable=False, null=True)
|
|
|
|
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
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2011-02-14 06:51:40 +08:00
|
|
|
class Musician(models.Model):
|
|
|
|
name = models.CharField(max_length=30)
|
|
|
|
|
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
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
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)
|
|
|
|
group = models.ForeignKey(Group)
|
|
|
|
|
|
|
|
|
2011-02-14 06:51:40 +08:00
|
|
|
class Membership(models.Model):
|
|
|
|
music = models.ForeignKey(Musician)
|
|
|
|
group = models.ForeignKey(Group)
|
|
|
|
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):
|
|
|
|
player = models.ForeignKey(ChordsMusician)
|
|
|
|
band = models.ForeignKey(ChordsBand)
|
|
|
|
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):
|
|
|
|
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):
|
|
|
|
swallow = models.OneToOneField(Swallow)
|
|
|
|
|
|
|
|
|
2012-03-03 10:13:35 +08:00
|
|
|
class UnorderedObject(models.Model):
|
|
|
|
"""
|
|
|
|
Model without any defined `Meta.ordering`.
|
|
|
|
Refs #17198.
|
|
|
|
"""
|
|
|
|
bool = models.BooleanField(default=True)
|
|
|
|
|
|
|
|
|
|
|
|
class OrderedObjectManager(models.Manager):
|
2013-03-08 22:15:23 +08:00
|
|
|
def get_queryset(self):
|
|
|
|
return super(OrderedObjectManager, self).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.
|
|
|
|
"""
|
|
|
|
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)
|