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.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
import datetime import datetime
from fields import MultiSelectField, MultiSelectFormField from django.contrib.localflavor.in_.forms import INZipCodeField
import multilingual from oxdjango.fields import DictField
from django.utils.translation import ugettext as _
EVENT_TYPES = ( GENDER_CHOICES = (
('workshop', 'Workshop'), ('M', 'Male'),
('seminar', 'Seminar'), ('F', 'Female'),
('exhibition', 'Exhibition'),
('course', 'Course / Training'),
('other', 'Other'),
) )
OCCUPATION_TYPES = ( class Person(models.Model):
('make_up_artist', 'Make-up Artist'),
('director', 'Director'),
('actor', 'Actor'),
('other', 'Other'),
)
FILE_TYPES = ( #Basic Info
('audio', 'Audio'), user = models.ForeignKey(User, blank=True, null=True, db_index=True)
('video', 'Video'), first_name = models.CharField(max_length=255)
('pdf', 'PDF'), last_name = models.CharField(max_length=255, blank=True)
('text', 'Text Document'), email = models.EmailField(blank=True, null=True, unique=True, db_index=True)
('other', 'Other'), tel_no = models.CharField(max_length=100, blank=True)
) about = models.TextField(blank=True, null=True)
PP_RELATION_TYPES = ( #Occupation info
('friend', 'Friend'), occupations = models.ManyToManyField("Occupation", through='PersonOccupation', blank=True, null=True)
('worked_under', 'Worked Under'), is_practitioner = models.BooleanField(default=False)
('worked_with', 'Worked with'), is_enthusiast = models.BooleanField(default=True)
('directed', 'Directed'),
('fanof', 'Fan Of'), #Personal info
('other', 'Other'), 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)
PG_RELATION_TYPES = ( locations = models.ManyToManyField("Location", blank=True, null=True)
('member', 'Member'),
('admin', 'Admin'), #Groups and Connections
('fan', 'Fan'), is_freelancer = models.BooleanField(default=False)
('other', 'Other'), 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')
class Script(models.Model): # trainings = models.ManyToManyField("Training", blank=True, null=True)
author = models.CharField(max_length=255) photos = models.ManyToManyField("PhotoAlbum", blank=True, null=True)
downloads = models.ManyToManyField('File', blank=True) # orphans = models.ManyToManyField("Orphan", blank=True, null=True, through='PersonOrphan')
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)
def __unicode__(self): def __unicode__(self):
return self.title return self.first_name + " " + self.last_name
class ProfileProduction(models.Model): def is_orphan(self):
profile = models.ForeignKey('Profile') return self.user == None
production = models.ForeignKey('Production')
role = models.CharField(max_length=255) class PhotoAlbum(models.Model):
is_approved = models.BooleanField(default=False) name = models.CharField(max_length=512)
is_original = models.BooleanField(default=False)
def __unicode__(self):
return self.role
class Meta:
verbose_name = 'Peoples Role in Production'
class Production(models.Model):
title = models.CharField(max_length=255)
description = models.TextField(blank=True) 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): def __unicode__(self):
return self.title return name
#class Nickname2(models.Model): class Photo(models.Model):
# name = models.CharField('Nick2', max_length=255, blank=True) image = models.ImageField(upload_to='photos/') # PLEASE CHANGE UPLOAD_TO TO A FUNCTION THAT RETURNS A SANE FOLDER NAME AND CREATES IT.
## nick_profile = models.ForeignKey('Profile') caption = models.TextField(blank=True)
exif = DictField(blank=True)
album = models.ForeignKey("PhotoAlbum")
# def __unicode__(self): class Occupation(models.Model):
# 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):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
location = models.ForeignKey('Location') parent = models.ForeignKey('Occupation', blank=True, null=True)
images = models.ManyToManyField('Image', blank=True)
links = models.ManyToManyField('Link', blank=True)
slug = models.SlugField()
def __unicode__(self): def __unicode__(self):
return self.name return self.name
class Performance(models.Model): def is_child(self):
production = models.ForeignKey('Production') return self.parent != None
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 __unicode__(self):
return self.production
class Meta: def is_parent(self):
get_latest_by = "datetime" if self.is_child():
return False
else:
if Occupation.objects.filter(parent=self).count() > 0: #self has children
return True
return False
class Event(models.Model): class PersonOccupation(models.Model):
title = models.CharField(max_length=255, blank=True) person = models.ForeignKey(Person, db_index=True)
synopsis = models.TextField(blank=True) occupation = models.ForeignKey(Occupation)
venue = models.ForeignKey('Venue') order = models.IntegerField()
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) # Orphans was a ridiculous concept. Orphans are Persons too. They just don't have a django auth user entry.
cost = models.CharField(max_length=255, blank=True) class Orphan(models.Model):
language = models.ForeignKey("Language", blank=True, null=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)
# 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): def __unicode__(self):
return self.title return name
class Language(models.Model):
name = models.CharField(max_length=100)
short_name = models.CharField(max_length=3)
class Location(models.Model): class Location(models.Model):
address = models.TextField(blank=True) address = models.TextField(blank=True, null=True)
lat = models.CharField(max_length=255, blank=True, verbose_name="Latitude", editable=False) city = models.CharField(blank=True, max_length=255, db_index=True)
lon = models.CharField(max_length=255, blank=True, verbose_name="Longitude", editable=False) pin_code = INZipCodeField()
def __unicode__(self): lat = models.FloatField(blank=True, null=True)
return self.address lng = models.FloatField(blank=True, null=True)
class ProfileProfile(models.Model): class Training(models.Model):
fromProfile = models.ForeignKey('Profile', related_name='relatedFrom', verbose_name="From Profile") person = models.ForeignKey("Person")
toProfile = models.ForeignKey('Profile', related_name='relatedTo', verbose_name="To Profile") area = models.CharField(max_length=255) # Choices?
rel_type = MultiSelectField(max_length=1000, choices=PP_RELATION_TYPES, verbose_name="Relation Type") with_whom = models.CharField(max_length=255) # Is this a foreign key to person, or group, or just text field like now?
is_approved = models.BooleanField(default=False) 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): class TheatreGroup(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255, db_index=True)
about = models.TextField(blank=True) city = models.CharField(max_length=255)
location = models.ManyToManyField('Location', blank=True) location = models.ForeignKey(Location, blank=True, null=True)
images = models.ManyToManyField('Image', blank=True) tel = models.IntegerField(blank=True, null=True)
files = models.ManyToManyField('File', blank=True) email = models.EmailField(blank=True, null=True)
links = models.ManyToManyField('Link', blank=True) about = models.TextField(blank=True, null=True)
slug = models.SlugField() nature_of_work = models.CharField(max_length=255)
def __unicode__(self): founded = models.CharField(max_length=10)
return self.name
class ProfileGroup(models.Model):
profile = models.ForeignKey('Profile') class PersonGroup(models.Model):
group = models.ForeignKey('TheatreGroup') person = models.ForeignKey(Person, db_index=True)
rel_type = MultiSelectField(max_length=1000, choices=PG_RELATION_TYPES, verbose_name="Relation Type") group = models.ForeignKey(TheatreGroup, db_index=True)
is_approved = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False) is_admin = models.BooleanField(default=False)
role = models.CharField(max_length=255, blank=True)
class Meta: class Language(models.Model):
verbose_name = 'Person to Theatre Group Relation' code = models.CharField(max_length=3, db_index=True)
name = models.CharField(max_length=255)
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