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