it/itf/itfprofiles/models.py

173 lines
6.3 KiB
Python
Raw Normal View History

2012-02-02 10:43:34 +00:00
from django.db import models
from app.models import ItfModel
from django.contrib.auth.models import User
2012-04-21 10:35:01 +00:00
from datetime import datetime
from django.contrib.localflavor.in_.forms import INZipCodeField
#from ox.django.fields import DictField
2012-02-02 10:43:34 +00:00
2012-04-21 10:35:01 +00:00
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
('O', 'Other'),
)
2012-02-02 10:43:34 +00:00
2012-04-21 10:35:01 +00:00
class Person(ItfModel):
#ItfModel stuff:
form_names = ['PersonForm']
fts_fields = ['first_name', 'last_name', 'email', 'about']
#Basic Info
user = models.ForeignKey(User, blank=True, null=True, db_index=True, editable=False)
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
email = models.EmailField(blank=True, null=True, unique=True, db_index=True)
email_validated = models.BooleanField(default=False, editable=False)
tel_no = models.CharField(max_length=100, blank=True)
about = models.TextField(blank=True, null=True)
2012-02-02 10:43:34 +00:00
2012-04-21 10:35:01 +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, related_name="trainee")
# photos = models.ManyToManyField("PhotoAlbum", blank=True, null=True)
# orphans = models.ManyToManyField("Orphan", blank=True, null=True, through='PersonOrphan')
2012-02-02 10:43:34 +00:00
2012-04-21 10:35:01 +00:00
#Meta
last_accessed = models.DateTimeField(default=datetime.now)
2012-02-02 10:43:34 +00:00
2012-04-21 10:35:01 +00:00
#Tokens
reset_token = models.CharField(max_length=256, null=True, editable=False)
validate_token = models.CharField(max_length=256, null=True, editable=False)
def __unicode__(self):
return "%s %s" % (self.first_name, self.last_name,)
class Occupation(models.Model):
name = models.CharField(max_length=255)
parent = models.ForeignKey('Occupation', blank=True, null=True)
def __unicode__(self):
return self.name
def is_child(self):
return self.parent != None
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()
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")
disapproved = models.BooleanField(default=False)
class Relation(models.Model):
name = models.CharField(max_length=255, db_index=True)
reverse = models.CharField(max_length=255, db_index=True)
def __unicode__(self):
return self.name
class Location(models.Model):
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)
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?
where = models.ForeignKey("TheatreGroup")
from_when = models.DateField(blank=True, null=True)
until_when = models.DateField(blank=True, null=True)
class Play(ItfModel):
title = models.CharField(max_length=512)
author = models.CharField(max_length=512, blank=True)
year = models.IntegerField(null=True, blank=True, max_length=4)
user = models.ForeignKey(User)
def __unicode__(self):
return self.title
class Production(ItfModel):
play = models.ForeignKey("Play", null=True, blank=True)
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.
)
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)
class TheatreGroup(ItfModel):
name = models.CharField(max_length=255, db_index=True) # name + location is unique
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)
def __unicode__(self):
return self.name
class PersonGroup(models.Model):
person = models.ForeignKey(Person, db_index=True)
group = models.ForeignKey(TheatreGroup, db_index=True)
is_admin = models.BooleanField(default=False)
role = models.CharField(max_length=255, blank=True)
class Language(models.Model):
code = models.CharField(max_length=3, db_index=True)
name = models.CharField(max_length=255)
2012-02-02 10:43:34 +00:00