it/itf/itfcore/models.py

173 lines
6.2 KiB
Python
Raw Normal View History

2010-03-03 14:28:00 +00:00
from django.db import models
from django.contrib.auth.models import User
import datetime
2010-08-28 22:21:55 +00:00
from django.contrib.localflavor.in_.forms import INZipCodeField
from ox.django.fields import DictField
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
('O', 'Other'),
2010-03-03 14:28:00 +00:00
)
2010-08-28 22:21:55 +00:00
class Person(models.Model):
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
#Basic Info
user = models.ForeignKey(User, blank=True, null=True, db_index=True)
first_name = models.CharField(max_length=255)
2010-10-21 16:51:01 +00:00
last_name = models.CharField(max_length=255)
2010-08-28 22:21:55 +00:00
email = models.EmailField(blank=True, null=True, unique=True, db_index=True)
tel_no = models.CharField(max_length=100, blank=True)
about = models.TextField(blank=True, null=True)
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
#Occupation info
occupations = models.ManyToManyField("Occupation", through='PersonOccupation', blank=True, null=True)
is_practitioner = models.BooleanField(default=False)
is_enthusiast = models.BooleanField(default=True)
#Personal info
dob = models.DateField(null=True, verbose_name="Date of Birth")
gender = models.CharField(max_length=255, choices=GENDER_CHOICES, blank=True)
image = models.ImageField(upload_to='images/', blank=True, null=True)
locations = models.ManyToManyField("Location", blank=True, null=True)
#Groups and Connections
is_freelancer = models.BooleanField(default=False)
groups = models.ManyToManyField("TheatreGroup", blank=True, null=True, through='PersonGroup')
connections = models.ManyToManyField('Person', blank=True, null=True, through='PersonPerson')
productions = models.ManyToManyField("Production", blank=True, null=True, through='PersonProduction')
# trainings = models.ManyToManyField("Training", blank=True, null=True)
photos = models.ManyToManyField("PhotoAlbum", blank=True, null=True)
# orphans = models.ManyToManyField("Orphan", blank=True, null=True, through='PersonOrphan')
2010-03-03 14:28:00 +00:00
def __unicode__(self):
2010-08-28 22:21:55 +00:00
return self.first_name + " " + self.last_name
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
def is_orphan(self):
return self.user == None
class PhotoAlbum(models.Model):
name = models.CharField(max_length=512)
2010-03-03 14:28:00 +00:00
description = models.TextField(blank=True)
def __unicode__(self):
2010-08-28 22:21:55 +00:00
return name
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
class Photo(models.Model):
image = models.ImageField(upload_to='photos/') # PLEASE CHANGE UPLOAD_TO TO A FUNCTION THAT RETURNS A SANE FOLDER NAME AND CREATES IT.
caption = models.TextField(blank=True)
exif = models.TextField(blank=True)
2010-08-28 22:21:55 +00:00
album = models.ForeignKey("PhotoAlbum")
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
class Occupation(models.Model):
2010-03-03 14:28:00 +00:00
name = models.CharField(max_length=255)
2010-08-28 22:21:55 +00:00
parent = models.ForeignKey('Occupation', blank=True, null=True)
2010-03-03 14:28:00 +00:00
def __unicode__(self):
return self.name
2010-08-28 22:21:55 +00:00
def is_child(self):
return self.parent != None
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
def is_parent(self):
if self.is_child():
return False
else:
if Occupation.objects.filter(parent=self).count() > 0: #self has children
return True
return False
class PersonOccupation(models.Model):
person = models.ForeignKey(Person, db_index=True)
occupation = models.ForeignKey(Occupation)
order = models.IntegerField()
'''
# Orphans was a ridiculous concept. Orphans are Persons too. They just don't have a django auth user entry.
class Orphan(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255, blank=True)
email = models.EmailField(blank=True, null=True, unique=True)
# about = models.TextField(blank=True, null=True)
class PersonOrphan(models.Model):
person = models.ForeignKey(Person)
orphan = models.ForeignKey(Orphan)
relation = models.ForeignKey("Relation")
'''
class PersonPerson(models.Model):
person1 = models.ForeignKey(Person, related_name='PersonFrom', db_index=True)
person2 = models.ForeignKey(Person, related_name='PersonTo', db_index=True)
relation = models.ForeignKey("Relation")
2010-10-21 16:51:01 +00:00
disapproved = models.BooleanField(default=False)
2010-08-28 22:21:55 +00:00
class Relation(models.Model):
name = models.CharField(max_length=255, db_index=True)
reverse = models.CharField(max_length=255, db_index=True)
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
def __unicode__(self):
return name
2010-03-03 14:28:00 +00:00
class Location(models.Model):
2010-08-28 22:21:55 +00:00
address = models.TextField(blank=True, null=True)
city = models.CharField(blank=True, max_length=255, db_index=True)
pin_code = INZipCodeField()
lat = models.FloatField(blank=True, null=True)
lng = models.FloatField(blank=True, null=True)
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
class Training(models.Model):
person = models.ForeignKey("Person")
area = models.CharField(max_length=255) # Choices?
with_whom = models.CharField(max_length=255) # Is this a foreign key to person, or group, or just text field like now?
2010-10-21 16:51:01 +00:00
where = models.ForeignKey("TheatreGroup")
2010-08-28 22:21:55 +00:00
from_when = models.DateField(blank=True, null=True)
until_when = models.DateField(blank=True, null=True)
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
class Production(models.Model):
name = models.CharField(max_length=255, db_index=True)
language = models.ForeignKey("Language", blank=True, null=True)
group = models.ForeignKey("TheatreGroup")
director = models.ForeignKey(Person)
SHOWS_NO_CHOICES = (
('5', '0-5 Shows'),
('10', '6-10 Shows'),
('50', '11-50 Shows'),
('100', '51-100 Shows'),
('1000', 'More Than 100 Shows'),
#add more.
)
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
class PersonProduction(models.Model):
person = models.ForeignKey(Person, db_index=True)
production = models.ForeignKey(Production, db_index=True)
role = models.CharField(max_length=255)
start_year = models.IntegerField(max_length=4)
years = models.IntegerField(blank=True, null=True)
no_of_shows = models.CharField(max_length=25, choices = SHOWS_NO_CHOICES)
original_cast = models.BooleanField(default=False)
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
class TheatreGroup(models.Model):
2010-10-21 16:51:01 +00:00
name = models.CharField(max_length=255, db_index=True) # name + location is unique
2010-08-28 22:21:55 +00:00
city = models.CharField(max_length=255)
location = models.ForeignKey(Location, blank=True, null=True)
tel = models.IntegerField(blank=True, null=True)
email = models.EmailField(blank=True, null=True)
about = models.TextField(blank=True, null=True)
nature_of_work = models.CharField(max_length=255)
founded = models.CharField(max_length=10)
class PersonGroup(models.Model):
person = models.ForeignKey(Person, db_index=True)
group = models.ForeignKey(TheatreGroup, db_index=True)
2010-03-03 14:28:00 +00:00
is_admin = models.BooleanField(default=False)
2010-08-28 22:21:55 +00:00
role = models.CharField(max_length=255, blank=True)
2010-03-03 14:28:00 +00:00
2010-08-28 22:21:55 +00:00
class Language(models.Model):
code = models.CharField(max_length=3, db_index=True)
name = models.CharField(max_length=255)