2018-01-31 18:43:05 +00:00
|
|
|
import uuid
|
|
|
|
|
2009-01-16 15:32:31 +00:00
|
|
|
from django.contrib.auth.models import User
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.db import models
|
2008-07-18 23:54:34 +00:00
|
|
|
|
2010-11-22 21:55:29 +00:00
|
|
|
|
|
|
|
class MyFileField(models.FileField):
|
|
|
|
pass
|
2009-04-08 20:25:56 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
class Member(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2009-01-16 15:32:31 +00:00
|
|
|
birthdate = models.DateTimeField(blank=True, null=True)
|
2013-10-26 19:15:03 +00:00
|
|
|
gender = models.CharField(max_length=1, blank=True, choices=[('M', 'Male'), ('F', 'Female')])
|
2013-07-26 11:22:30 +00:00
|
|
|
email = models.EmailField(blank=True)
|
2008-09-01 22:43:38 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2008-07-18 23:54:34 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2021-03-18 10:21:23 +00:00
|
|
|
class Artist(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Band(Artist):
|
2021-01-12 10:37:38 +00:00
|
|
|
uuid = models.UUIDField(unique=True, default=uuid.uuid4)
|
2008-07-18 23:54:34 +00:00
|
|
|
name = models.CharField(max_length=100)
|
2012-12-08 11:41:11 +00:00
|
|
|
style = models.CharField(max_length=20)
|
2008-07-18 23:54:34 +00:00
|
|
|
members = models.ManyToManyField(Member)
|
2008-09-01 22:43:38 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2008-07-18 23:54:34 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2020-05-26 07:51:02 +00:00
|
|
|
class UnsafeLimitChoicesTo(models.Model):
|
|
|
|
band = models.ForeignKey(
|
|
|
|
Band,
|
|
|
|
models.CASCADE,
|
|
|
|
limit_choices_to={'name': '"&><escapeme'},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2008-07-18 23:54:34 +00:00
|
|
|
class Album(models.Model):
|
2021-01-12 10:37:38 +00:00
|
|
|
band = models.ForeignKey(Band, models.CASCADE, to_field='uuid')
|
2017-05-10 12:48:57 +00:00
|
|
|
featuring = models.ManyToManyField(Band, related_name='featured')
|
2008-07-18 23:54:34 +00:00
|
|
|
name = models.CharField(max_length=100)
|
2008-08-08 23:06:28 +00:00
|
|
|
cover_art = models.FileField(upload_to='albums')
|
2009-04-08 20:25:56 +00:00
|
|
|
backside_art = MyFileField(upload_to='albums_back', null=True)
|
2008-09-01 22:43:38 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2008-07-18 23:54:34 +00:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2021-03-18 10:21:23 +00:00
|
|
|
class ReleaseEvent(models.Model):
|
|
|
|
"""
|
|
|
|
Used to check that autocomplete widget correctly resolves attname for FK as
|
|
|
|
PK example.
|
|
|
|
"""
|
|
|
|
album = models.ForeignKey(Album, models.CASCADE, primary_key=True)
|
|
|
|
name = models.CharField(max_length=100)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ['name']
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class VideoStream(models.Model):
|
|
|
|
release_event = models.ForeignKey(ReleaseEvent, models.CASCADE)
|
|
|
|
|
|
|
|
|
2008-11-15 02:20:00 +00:00
|
|
|
class HiddenInventoryManager(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().filter(hidden=False)
|
2008-11-15 02:20:00 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2008-09-01 22:43:38 +00:00
|
|
|
class Inventory(models.Model):
|
2013-09-03 18:22:21 +00:00
|
|
|
barcode = models.PositiveIntegerField(unique=True)
|
2015-07-22 14:43:21 +00:00
|
|
|
parent = models.ForeignKey('self', models.SET_NULL, to_field='barcode', blank=True, null=True)
|
2013-09-03 18:22:21 +00:00
|
|
|
name = models.CharField(blank=False, max_length=20)
|
|
|
|
hidden = models.BooleanField(default=False)
|
2009-01-16 21:18:21 +00:00
|
|
|
|
2013-09-03 18:22:21 +00:00
|
|
|
# see #9258
|
|
|
|
default_manager = models.Manager()
|
|
|
|
objects = HiddenInventoryManager()
|
2008-09-01 22:43:38 +00:00
|
|
|
|
2013-09-03 18:22:21 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2009-01-16 21:18:21 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-01-16 15:32:31 +00:00
|
|
|
class Event(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
main_band = models.ForeignKey(
|
|
|
|
Band,
|
|
|
|
models.CASCADE,
|
|
|
|
limit_choices_to=models.Q(pk__gt=0),
|
|
|
|
related_name='events_main_band_at',
|
|
|
|
)
|
2016-01-29 21:21:21 +00:00
|
|
|
supporting_bands = models.ManyToManyField(
|
|
|
|
Band,
|
|
|
|
blank=True,
|
|
|
|
related_name='events_supporting_band_at',
|
|
|
|
help_text='Supporting Bands.',
|
|
|
|
)
|
2009-01-16 21:18:21 +00:00
|
|
|
start_date = models.DateField(blank=True, null=True)
|
2009-01-16 15:32:31 +00:00
|
|
|
start_time = models.TimeField(blank=True, null=True)
|
|
|
|
description = models.TextField(blank=True)
|
|
|
|
link = models.URLField(blank=True)
|
|
|
|
min_age = models.IntegerField(blank=True, null=True)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-01-16 15:32:31 +00:00
|
|
|
class Car(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
owner = models.ForeignKey(User, models.CASCADE)
|
2009-01-16 15:32:31 +00:00
|
|
|
make = models.CharField(max_length=30)
|
|
|
|
model = models.CharField(max_length=30)
|
2009-01-16 21:18:21 +00:00
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
return "%s %s" % (self.make, self.model)
|
2009-01-16 15:32:31 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2009-01-16 15:32:31 +00:00
|
|
|
class CarTire(models.Model):
|
|
|
|
"""
|
|
|
|
A single car tire. This to test that a user can only select their own cars.
|
|
|
|
"""
|
2015-07-22 14:43:21 +00:00
|
|
|
car = models.ForeignKey(Car, models.CASCADE)
|
2011-08-01 23:38:11 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-08-01 23:38:11 +00:00
|
|
|
class Honeycomb(models.Model):
|
2018-01-31 18:43:05 +00:00
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
2011-08-01 23:38:11 +00:00
|
|
|
location = models.CharField(max_length=20)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-08-01 23:38:11 +00:00
|
|
|
class Bee(models.Model):
|
|
|
|
"""
|
|
|
|
A model with a FK to a model that won't be registered with the admin
|
|
|
|
(Honeycomb) so the corresponding raw ID widget won't have a magnifying
|
|
|
|
glass link to select related honeycomb instances.
|
|
|
|
"""
|
2015-07-22 14:43:21 +00:00
|
|
|
honeycomb = models.ForeignKey(Honeycomb, models.CASCADE)
|
2011-08-01 23:38:11 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-08-01 23:38:11 +00:00
|
|
|
class Individual(models.Model):
|
|
|
|
"""
|
|
|
|
A model with a FK to itself. It won't be registered with the admin, so the
|
|
|
|
corresponding raw ID widget won't have a magnifying glass link to select
|
|
|
|
related instances (rendering will be called programmatically in this case).
|
|
|
|
"""
|
|
|
|
name = models.CharField(max_length=20)
|
2015-07-22 14:43:21 +00:00
|
|
|
parent = models.ForeignKey('self', models.SET_NULL, null=True)
|
|
|
|
soulmate = models.ForeignKey('self', models.CASCADE, null=True, related_name='soulmates')
|
2011-08-01 23:38:11 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-08-01 23:38:11 +00:00
|
|
|
class Company(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2011-08-01 23:38:11 +00:00
|
|
|
class Advisor(models.Model):
|
|
|
|
"""
|
|
|
|
A model with a m2m to a model that won't be registered with the admin
|
|
|
|
(Company) so the corresponding raw ID widget won't have a magnifying
|
|
|
|
glass link to select related company instances.
|
|
|
|
"""
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
companies = models.ManyToManyField(Company)
|
2012-02-23 08:07:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Student(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
2018-12-28 00:34:14 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2012-02-23 08:07:07 +00:00
|
|
|
class School(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
students = models.ManyToManyField(Student, related_name='current_schools')
|
|
|
|
alumni = models.ManyToManyField(Student, related_name='previous_schools')
|
|
|
|
|
2012-08-12 10:32:08 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2013-09-07 16:52:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Profile(models.Model):
|
2015-07-22 14:43:21 +00:00
|
|
|
user = models.ForeignKey('auth.User', models.CASCADE, to_field='username')
|
2013-09-07 16:52:14 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.user.username
|