added db_indexes, validates

This commit is contained in:
sanj 2010-08-29 03:51:55 +05:30
parent b4e8dd665a
commit 6c4ccfc99a

View File

@ -1,253 +1,171 @@
from django.db import models
from django.contrib.auth.models import User
import datetime
from fields import MultiSelectField, MultiSelectFormField
import multilingual
from django.utils.translation import ugettext as _
from django.contrib.localflavor.in_.forms import INZipCodeField
from oxdjango.fields import DictField
EVENT_TYPES = (
('workshop', 'Workshop'),
('seminar', 'Seminar'),
('exhibition', 'Exhibition'),
('course', 'Course / Training'),
('other', 'Other'),
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
OCCUPATION_TYPES = (
('make_up_artist', 'Make-up Artist'),
('director', 'Director'),
('actor', 'Actor'),
('other', 'Other'),
)
class Person(models.Model):
FILE_TYPES = (
('audio', 'Audio'),
('video', 'Video'),
('pdf', 'PDF'),
('text', 'Text Document'),
('other', 'Other'),
)
#Basic Info
user = models.ForeignKey(User, blank=True, null=True, db_index=True)
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, db_index=True)
tel_no = models.CharField(max_length=100, blank=True)
about = models.TextField(blank=True, null=True)
PP_RELATION_TYPES = (
('friend', 'Friend'),
('worked_under', 'Worked Under'),
('worked_with', 'Worked with'),
('directed', 'Directed'),
('fanof', 'Fan Of'),
('other', 'Other'),
)
#Occupation info
occupations = models.ManyToManyField("Occupation", through='PersonOccupation', blank=True, null=True)
is_practitioner = models.BooleanField(default=False)
is_enthusiast = models.BooleanField(default=True)
PG_RELATION_TYPES = (
('member', 'Member'),
('admin', 'Admin'),
('fan', 'Fan'),
('other', 'Other'),
)
#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)
class Script(models.Model):
author = models.CharField(max_length=255)
downloads = models.ManyToManyField('File', blank=True)
links = models.ManyToManyField('Link', blank=True)
language = models.CharField(max_length=50, blank=True)
class Translation(multilingual.Translation):
title = models.CharField(max_length=255)
synopsis = models.TextField(blank=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')
def __unicode__(self):
return self.title
return self.first_name + " " + self.last_name
class ProfileProduction(models.Model):
profile = models.ForeignKey('Profile')
production = models.ForeignKey('Production')
role = models.CharField(max_length=255)
is_approved = models.BooleanField(default=False)
is_original = models.BooleanField(default=False)
def __unicode__(self):
return self.role
def is_orphan(self):
return self.user == None
class Meta:
verbose_name = 'Peoples Role in Production'
class Production(models.Model):
title = models.CharField(max_length=255)
class PhotoAlbum(models.Model):
name = models.CharField(max_length=512)
description = models.TextField(blank=True)
author = models.ForeignKey('Profile', related_name="AuthoredProduction")
director = models.ForeignKey('Profile', related_name="DirectedProduction")
cast = models.ManyToManyField('Profile', through='ProfileProduction', blank=True, symmetrical=False)
theatregroup = models.ForeignKey('TheatreGroup', blank=True, null=True, verbose_name="Theatre Group")
script = models.ForeignKey('Script', blank=True, null=True)
images = models.ManyToManyField('Image', blank=True)
files = models.ManyToManyField('File', blank=True)
links = models.ManyToManyField('Link', blank=True)
language = models.CharField(max_length=50, blank=True)
slug = models.SlugField()
def get_absolute_url(self):
return "/production/" + str(self.id)
def __unicode__(self):
return self.title
return name
#class Nickname2(models.Model):
# name = models.CharField('Nick2', max_length=255, blank=True)
## nick_profile = models.ForeignKey('Profile')
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 = DictField(blank=True)
album = models.ForeignKey("PhotoAlbum")
# def __unicode__(self):
# return self.name
#class Nickname3(models.Model):
# name = models.CharField('Nick3', max_length=255, blank=True)
## nick_profile = models.ForeignKey('Profile')
# def __unicode__(self):
# return self.name
class Nickname(models.Model):
name = models.CharField('Nick', max_length=255, blank=True)
profile = models.ForeignKey('Profile')
def __unicode__(self):
return self.name
class Profile(models.Model):
user = models.ForeignKey(User, blank=True, unique=True, null=True)
phone = models.CharField(max_length=255, blank=True)
email = models.CharField(max_length=255, blank=True, db_index=True)
groups = models.ManyToManyField('TheatreGroup', through='ProfileGroup', blank=True, symmetrical=False)
occupation = MultiSelectField(max_length=1000, choices=OCCUPATION_TYPES, verbose_name="Occupation Type", blank=True)
connections = models.ManyToManyField('Profile', through='ProfileProfile', blank=True, symmetrical=False)
profile_image = models.ForeignKey('Image', blank=True, null=True, related_name="profile_image")
dob = models.DateField(blank=True, verbose_name="DoB", null=True)
location = models.ForeignKey('Location', blank=True, null=True)
images = models.ManyToManyField('Image', blank=True)
files = models.ManyToManyField('File', blank=True)
links = models.ManyToManyField('Link', blank=True)
related_productions = models.ManyToManyField('Production', blank=True, null=True)
# nickname = models.ForeignKey(Nickname, blank=True, null=True)
# nickname2 = models.ForeignKey('Nickname2', related_name="MyNick", blank=True)
# nickname3 = models.ManyToManyField('Nickname3', blank=True)
class Translation(multilingual.Translation):
firstname = models.CharField(max_length=255, verbose_name=_("First Name"))
lastname = models.CharField(max_length=255, blank=True, verbose_name=_("Last Name"))
about = models.TextField(blank=True)
def __unicode__(self):
return self.firstname + " " + self.lastname
class Venue(models.Model):
class Occupation(models.Model):
name = models.CharField(max_length=255)
location = models.ForeignKey('Location')
images = models.ManyToManyField('Image', blank=True)
links = models.ManyToManyField('Link', blank=True)
slug = models.SlugField()
parent = models.ForeignKey('Occupation', blank=True, null=True)
def __unicode__(self):
return self.name
class Performance(models.Model):
production = models.ForeignKey('Production')
venue = models.ForeignKey('Venue', blank=True, null=True)
datetime = models.DateTimeField(verbose_name="Date & Time", blank=True, null=True)
ticketslink = models.URLField(max_length=255, blank=True, verbose_name="Tickets link")
images = models.ManyToManyField('Image', blank=True)
links = models.ManyToManyField('Link', blank=True)
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()
'''
# 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")
approved = 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.production
class Meta:
get_latest_by = "datetime"
class Event(models.Model):
title = models.CharField(max_length=255, blank=True)
synopsis = models.TextField(blank=True)
venue = models.ForeignKey('Venue')
theatregroup = models.ForeignKey('TheatreGroup', blank=True, null=True, verbose_name="Theatre Group")
time = models.DateTimeField(blank=True, null=True)
eventtype = models.CharField(max_length=255, choices=EVENT_TYPES, verbose_name="Event Type")
links = models.ManyToManyField('Link', blank=True)
cost = models.CharField(max_length=255, blank=True)
language = models.ForeignKey("Language", blank=True, null=True)
def __unicode__(self):
return self.title
class Language(models.Model):
name = models.CharField(max_length=100)
short_name = models.CharField(max_length=3)
return name
class Location(models.Model):
address = models.TextField(blank=True)
lat = models.CharField(max_length=255, blank=True, verbose_name="Latitude", editable=False)
lon = models.CharField(max_length=255, blank=True, verbose_name="Longitude", editable=False)
def __unicode__(self):
return self.address
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 ProfileProfile(models.Model):
fromProfile = models.ForeignKey('Profile', related_name='relatedFrom', verbose_name="From Profile")
toProfile = models.ForeignKey('Profile', related_name='relatedTo', verbose_name="To Profile")
rel_type = MultiSelectField(max_length=1000, choices=PP_RELATION_TYPES, verbose_name="Relation Type")
is_approved = models.BooleanField(default=False)
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?
location = models.ForeignKey("Location")
from_when = models.DateField(blank=True, null=True)
until_when = models.DateField(blank=True, null=True)
class Meta:
verbose_name = 'Person to Person Relation'
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.
)
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(models.Model):
name = models.CharField(max_length=255)
about = models.TextField(blank=True)
location = models.ManyToManyField('Location', blank=True)
images = models.ManyToManyField('Image', blank=True)
files = models.ManyToManyField('File', blank=True)
links = models.ManyToManyField('Link', blank=True)
slug = models.SlugField()
def __unicode__(self):
return self.name
name = models.CharField(max_length=255, db_index=True)
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 ProfileGroup(models.Model):
profile = models.ForeignKey('Profile')
group = models.ForeignKey('TheatreGroup')
rel_type = MultiSelectField(max_length=1000, choices=PG_RELATION_TYPES, verbose_name="Relation Type")
is_approved = models.BooleanField(default=False)
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 Meta:
verbose_name = 'Person to Theatre Group Relation'
class Image(models.Model):
image = models.ImageField(upload_to='/profiles/', width_field='width', height_field='height', null=False)
width = models.IntegerField(editable=False)
height = models.IntegerField(editable=False)
caption = models.CharField(max_length=255, blank=True)
def __unicode__(self):
if self.caption:
return self.caption
else:
return self.path
class File(models.Model):
file = models.FileField(upload_to='/uploads/')
file_type = models.CharField(max_length=255, choices=FILE_TYPES, verbose_name="File Type")
description = models.TextField(blank=True)
def __unicode__(self):
return self.caption
class RandomQuote(models.Model):
quote = models.TextField()
author = models.CharField(max_length=255)
class Link(models.Model):
url = models.URLField()
caption = models.CharField(max_length=255, blank=True)
# related_profile = models.ForeignKey(Profile)
def __unicode__(self):
if self.caption:
return self.caption
else:
return self.url
class Language(models.Model):
code = models.CharField(max_length=3, db_index=True)
name = models.CharField(max_length=255)