2022-10-17 10:02:56 +08:00
|
|
|
import tempfile
|
2018-02-01 02:43:05 +08:00
|
|
|
import uuid
|
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
from django.contrib.auth.models import User
|
2022-10-17 10:02:56 +08:00
|
|
|
from django.core.files.storage import FileSystemStorage
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.db import models
|
2008-07-19 07:54:34 +08:00
|
|
|
|
2022-10-27 14:41:03 +08:00
|
|
|
try:
|
|
|
|
from PIL import Image
|
|
|
|
except ImportError:
|
|
|
|
Image = None
|
|
|
|
else:
|
|
|
|
temp_storage_dir = tempfile.mkdtemp()
|
|
|
|
temp_storage = FileSystemStorage(temp_storage_dir)
|
2022-10-17 10:02:56 +08:00
|
|
|
|
2010-11-23 05:55:29 +08:00
|
|
|
|
|
|
|
class MyFileField(models.FileField):
|
|
|
|
pass
|
2009-04-09 04:25:56 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2008-07-19 07:54:34 +08:00
|
|
|
class Member(models.Model):
|
|
|
|
name = models.CharField(max_length=100)
|
2009-01-16 23:32:31 +08:00
|
|
|
birthdate = models.DateTimeField(blank=True, null=True)
|
2013-10-27 03:15:03 +08:00
|
|
|
gender = models.CharField(
|
|
|
|
max_length=1, blank=True, choices=[("M", "Male"), ("F", "Female")]
|
|
|
|
)
|
2013-07-26 19:22:30 +08:00
|
|
|
email = models.EmailField(blank=True)
|
2008-09-02 06:43:38 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-07-19 07:54:34 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2021-03-18 18:21:23 +08:00
|
|
|
class Artist(models.Model):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Band(Artist):
|
2021-01-12 18:37:38 +08:00
|
|
|
uuid = models.UUIDField(unique=True, default=uuid.uuid4)
|
2008-07-19 07:54:34 +08:00
|
|
|
name = models.CharField(max_length=100)
|
2012-12-08 19:41:11 +08:00
|
|
|
style = models.CharField(max_length=20)
|
2008-07-19 07:54:34 +08:00
|
|
|
members = models.ManyToManyField(Member)
|
2008-09-02 06:43:38 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-07-19 07:54:34 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2020-05-26 15:51:02 +08:00
|
|
|
class UnsafeLimitChoicesTo(models.Model):
|
|
|
|
band = models.ForeignKey(
|
|
|
|
Band,
|
|
|
|
models.CASCADE,
|
|
|
|
limit_choices_to={"name": '"&><escapeme'},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2008-07-19 07:54:34 +08:00
|
|
|
class Album(models.Model):
|
2021-01-12 18:37:38 +08:00
|
|
|
band = models.ForeignKey(Band, models.CASCADE, to_field="uuid")
|
2017-05-10 20:48:57 +08:00
|
|
|
featuring = models.ManyToManyField(Band, related_name="featured")
|
2008-07-19 07:54:34 +08:00
|
|
|
name = models.CharField(max_length=100)
|
2008-08-09 07:06:28 +08:00
|
|
|
cover_art = models.FileField(upload_to="albums")
|
2009-04-09 04:25:56 +08:00
|
|
|
backside_art = MyFileField(upload_to="albums_back", null=True)
|
2008-09-02 06:43:38 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2008-07-19 07:54:34 +08:00
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2021-03-18 18:21:23 +08:00
|
|
|
class ReleaseEvent(models.Model):
|
|
|
|
"""
|
|
|
|
Used to check that autocomplete widget correctly resolves attname for FK as
|
|
|
|
PK example.
|
|
|
|
"""
|
2022-02-04 03:24:19 +08:00
|
|
|
|
2021-03-18 18:21:23 +08:00
|
|
|
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 10:20:00 +08:00
|
|
|
class HiddenInventoryManager(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().filter(hidden=False)
|
2008-11-15 10:20:00 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2008-09-02 06:43:38 +08:00
|
|
|
class Inventory(models.Model):
|
2013-09-04 02:22:21 +08:00
|
|
|
barcode = models.PositiveIntegerField(unique=True)
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey(
|
|
|
|
"self", models.SET_NULL, to_field="barcode", blank=True, null=True
|
|
|
|
)
|
2013-09-04 02:22:21 +08:00
|
|
|
name = models.CharField(blank=False, max_length=20)
|
|
|
|
hidden = models.BooleanField(default=False)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2013-09-04 02:22:21 +08:00
|
|
|
# see #9258
|
|
|
|
default_manager = models.Manager()
|
|
|
|
objects = HiddenInventoryManager()
|
2008-09-02 06:43:38 +08:00
|
|
|
|
2013-09-04 02:22:21 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
class Event(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
main_band = models.ForeignKey(
|
|
|
|
Band,
|
|
|
|
models.CASCADE,
|
|
|
|
limit_choices_to=models.Q(pk__gt=0),
|
|
|
|
related_name="events_main_band_at",
|
|
|
|
)
|
2016-01-30 05:21:21 +08:00
|
|
|
supporting_bands = models.ManyToManyField(
|
|
|
|
Band,
|
|
|
|
blank=True,
|
|
|
|
related_name="events_supporting_band_at",
|
|
|
|
help_text="Supporting Bands.",
|
|
|
|
)
|
2009-01-17 05:18:21 +08:00
|
|
|
start_date = models.DateField(blank=True, null=True)
|
2009-01-16 23:32:31 +08: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 12:36:09 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
class Car(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
owner = models.ForeignKey(User, models.CASCADE)
|
2009-01-16 23:32:31 +08:00
|
|
|
make = models.CharField(max_length=30)
|
|
|
|
model = models.CharField(max_length=30)
|
2009-01-17 05:18:21 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-06-08 00:08:47 +08:00
|
|
|
return "%s %s" % (self.make, self.model)
|
2009-01-16 23:32:31 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
class CarTire(models.Model):
|
|
|
|
"""
|
|
|
|
A single car tire. This to test that a user can only select their own cars.
|
|
|
|
"""
|
2022-02-04 03:24:19 +08:00
|
|
|
|
2015-07-22 22:43:21 +08:00
|
|
|
car = models.ForeignKey(Car, models.CASCADE)
|
2011-08-02 07:38:11 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-08-02 07:38:11 +08:00
|
|
|
class Honeycomb(models.Model):
|
2018-02-01 02:43:05 +08:00
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
2011-08-02 07:38:11 +08:00
|
|
|
location = models.CharField(max_length=20)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-08-02 07:38:11 +08: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.
|
|
|
|
"""
|
2022-02-04 03:24:19 +08:00
|
|
|
|
2015-07-22 22:43:21 +08:00
|
|
|
honeycomb = models.ForeignKey(Honeycomb, models.CASCADE)
|
2011-08-02 07:38:11 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-08-02 07:38:11 +08: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).
|
|
|
|
"""
|
2022-02-04 03:24:19 +08:00
|
|
|
|
2011-08-02 07:38:11 +08:00
|
|
|
name = models.CharField(max_length=20)
|
2015-07-22 22:43:21 +08:00
|
|
|
parent = models.ForeignKey("self", models.SET_NULL, null=True)
|
|
|
|
soulmate = models.ForeignKey(
|
|
|
|
"self", models.CASCADE, null=True, related_name="soulmates"
|
|
|
|
)
|
2011-08-02 07:38:11 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-08-02 07:38:11 +08:00
|
|
|
class Company(models.Model):
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2011-08-02 07:38:11 +08: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.
|
|
|
|
"""
|
2022-02-04 03:24:19 +08:00
|
|
|
|
2011-08-02 07:38:11 +08:00
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
companies = models.ManyToManyField(Company)
|
2012-02-23 16:07:07 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Student(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
2022-10-27 14:41:03 +08:00
|
|
|
if Image:
|
|
|
|
photo = models.ImageField(
|
|
|
|
storage=temp_storage, upload_to="photos", blank=True, null=True
|
|
|
|
)
|
2012-02-23 16:07:07 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ("name",)
|
|
|
|
|
2018-12-28 08:34:14 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-02-23 16:07:07 +08: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 18:32:08 +08:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2013-09-08 00:52:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
class Profile(models.Model):
|
2015-07-22 22:43:21 +08:00
|
|
|
user = models.ForeignKey("auth.User", models.CASCADE, to_field="username")
|
2013-09-08 00:52:14 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.user.username
|