1
from __future__ import unicode_literals
3
from django.db import models
4
from django.contrib.auth.models import User
5
from django.utils.encoding import python_2_unicode_compatible
8
class MyFileField(models.FileField):
11
@python_2_unicode_compatible
12
class Member(models.Model):
13
name = models.CharField(max_length=100)
14
birthdate = models.DateTimeField(blank=True, null=True)
15
gender = models.CharField(max_length=1, blank=True, choices=[('M','Male'), ('F', 'Female')])
20
@python_2_unicode_compatible
21
class Band(models.Model):
22
name = models.CharField(max_length=100)
23
style = models.CharField(max_length=20)
24
members = models.ManyToManyField(Member)
29
@python_2_unicode_compatible
30
class Album(models.Model):
31
band = models.ForeignKey(Band)
32
name = models.CharField(max_length=100)
33
cover_art = models.FileField(upload_to='albums')
34
backside_art = MyFileField(upload_to='albums_back', null=True)
39
class HiddenInventoryManager(models.Manager):
40
def get_query_set(self):
41
return super(HiddenInventoryManager, self).get_query_set().filter(hidden=False)
43
@python_2_unicode_compatible
44
class Inventory(models.Model):
45
barcode = models.PositiveIntegerField(unique=True)
46
parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
47
name = models.CharField(blank=False, max_length=20)
48
hidden = models.BooleanField(default=False)
51
default_manager = models.Manager()
52
objects = HiddenInventoryManager()
57
class Event(models.Model):
58
band = models.ForeignKey(Band, limit_choices_to=models.Q(pk__gt=0))
59
start_date = models.DateField(blank=True, null=True)
60
start_time = models.TimeField(blank=True, null=True)
61
description = models.TextField(blank=True)
62
link = models.URLField(blank=True)
63
min_age = models.IntegerField(blank=True, null=True)
65
@python_2_unicode_compatible
66
class Car(models.Model):
67
owner = models.ForeignKey(User)
68
make = models.CharField(max_length=30)
69
model = models.CharField(max_length=30)
72
return "%s %s" % (self.make, self.model)
74
class CarTire(models.Model):
76
A single car tire. This to test that a user can only select their own cars.
78
car = models.ForeignKey(Car)
80
class Honeycomb(models.Model):
81
location = models.CharField(max_length=20)
83
class Bee(models.Model):
85
A model with a FK to a model that won't be registered with the admin
86
(Honeycomb) so the corresponding raw ID widget won't have a magnifying
87
glass link to select related honeycomb instances.
89
honeycomb = models.ForeignKey(Honeycomb)
91
class Individual(models.Model):
93
A model with a FK to itself. It won't be registered with the admin, so the
94
corresponding raw ID widget won't have a magnifying glass link to select
95
related instances (rendering will be called programmatically in this case).
97
name = models.CharField(max_length=20)
98
parent = models.ForeignKey('self', null=True)
100
class Company(models.Model):
101
name = models.CharField(max_length=20)
103
class Advisor(models.Model):
105
A model with a m2m to a model that won't be registered with the admin
106
(Company) so the corresponding raw ID widget won't have a magnifying
107
glass link to select related company instances.
109
name = models.CharField(max_length=20)
110
companies = models.ManyToManyField(Company)
113
@python_2_unicode_compatible
114
class Student(models.Model):
115
name = models.CharField(max_length=255)
123
@python_2_unicode_compatible
124
class School(models.Model):
125
name = models.CharField(max_length=255)
126
students = models.ManyToManyField(Student, related_name='current_schools')
127
alumni = models.ManyToManyField(Student, related_name='previous_schools')