2012-06-08 00:08:47 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2009-01-16 23:32:31 +08:00
|
|
|
from django.contrib.auth.models import User
|
2015-02-10 02:19:34 +08:00
|
|
|
from django.db import models
|
2012-08-12 18:32:08 +08:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2008-07-19 07:54:34 +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
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
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
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-07-19 07:54:34 +08:00
|
|
|
class Band(models.Model):
|
|
|
|
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
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2008-07-19 07:54:34 +08:00
|
|
|
class Album(models.Model):
|
|
|
|
band = models.ForeignKey(Band)
|
|
|
|
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
|
|
|
|
2008-11-15 10:20:00 +08:00
|
|
|
class HiddenInventoryManager(models.Manager):
|
2013-03-08 22:15:23 +08:00
|
|
|
def get_queryset(self):
|
|
|
|
return super(HiddenInventoryManager, self).get_queryset().filter(hidden=False)
|
2008-11-15 10:20:00 +08:00
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
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)
|
|
|
|
parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
|
|
|
|
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):
|
2013-08-05 07:06:47 +08:00
|
|
|
main_band = models.ForeignKey(Band, limit_choices_to=models.Q(pk__gt=0), related_name='events_main_band_at')
|
2014-07-09 04:42:40 +08:00
|
|
|
supporting_bands = models.ManyToManyField(Band, blank=True, related_name='events_supporting_band_at')
|
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
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2009-01-16 23:32:31 +08:00
|
|
|
class Car(models.Model):
|
|
|
|
owner = models.ForeignKey(User)
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
car = models.ForeignKey(Car)
|
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):
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
honeycomb = models.ForeignKey(Honeycomb)
|
|
|
|
|
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).
|
|
|
|
"""
|
|
|
|
name = models.CharField(max_length=20)
|
2013-11-18 06:26:20 +08:00
|
|
|
parent = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
|
|
|
|
soulmate = models.ForeignKey('self', null=True, on_delete=models.CASCADE, 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.
|
|
|
|
"""
|
|
|
|
name = models.CharField(max_length=20)
|
|
|
|
companies = models.ManyToManyField(Company)
|
2012-02-23 16:07:07 +08:00
|
|
|
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2012-02-23 16:07:07 +08:00
|
|
|
class Student(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-02-23 16:07:07 +08:00
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
ordering = ('name',)
|
|
|
|
|
2013-11-03 12:36:09 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
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
|
|
|
|
|
|
|
|
|
|
|
@python_2_unicode_compatible
|
|
|
|
class Profile(models.Model):
|
|
|
|
user = models.ForeignKey('auth.User', 'username')
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.user.username
|