create forms for events

This commit is contained in:
Sanj 2012-08-07 19:59:35 +05:30
parent 8949e52c76
commit 01f5996b02
4 changed files with 54 additions and 10 deletions

30
itf/events/forms.py Normal file
View File

@ -0,0 +1,30 @@
import floppyforms as forms
from models import *
from app.forms import *
from itfprofiles.models import Person, TheatreGroup
class PersonEventForm(ItfForm):
person = forms.ModelChoiceField(Person.objects.all(), widget=AutocompleteAddWidget(model_class=Person))
class Meta:
model = PersonEvent
class GroupEventForm(ItfForm):
group = forms.ModelChoiceField(TheatreGroup.objects.all(), widget=AutocompleteAddWidget(model_class=TheatreGroup))
class Meta:
model = GroupEvent
PersonEventInline = itf_inlineformset_factory(Event, PersonEvent, form=PersonEventForm, extra=1, title="Add / Edit people associated with this event", help_text="select the people that are connected to this event")
GroupEventInline = itf_inlineformset_factory(Event, GroupEvent, form=GroupEventForm, extra=1, title="Add / Edit groups associated with this event", help_text="select the groups that are connected to this event")
class EventForm(ItfForm):
inlines = [PersonEventInline, GroupEventInline]
class Meta:
model = Event
exclude = ('people', 'groups',)

View File

@ -12,13 +12,14 @@ from itfprofiles.models import Location, Production, TheatreGroup, Person
class Event(ItfModel):
#ItfModel stuff:
#form_names = ['PersonForm', 'PopupPersonForm']
form_names = ['EventForm']
main_form = 'EventForm'
fts_fields = ['title', 'oneliner', 'description']
title = models.CharField(max_length=1024)
oneliner = models.CharField(max_length=1024,help_text="Event slogan/one liner")
description = models.TextField(blank=True, null=True)
locations = generic.GenericRelation("Location")
locations = generic.GenericRelation(Location)
start_date = models.DateTimeField()
end_date = models.DateTimeField()
booking_link = models.URLField(blank=True, null=True, help_text="Ticket booking")
@ -26,7 +27,7 @@ class Event(ItfModel):
production = models.ForeignKey(Production, blank=True, null=True, help_text="If this is a showing of a production...")
people = models.ManyToManyField(Person, blank=True, null=True, through="PersonEvent")
image = models.ImageField(upload_to='images/', blank=True, null=True)
# groups = models.ManyToManyField(TheatreGroup,
groups = models.ManyToManyField(TheatreGroup, blank=True, null=True, through="GroupEvent")
#Entities and Connections -
# connections = generic.GenericRelation("Connection")
@ -39,12 +40,12 @@ class Event(ItfModel):
return self.__unicode__()
def get_dict(self):
links = self.connections.all().order_by('link_type')
link_keys = self.connections.all().values_list['link_type'].distinct()
# links = self.connections.all().order_by('link_type')
# link_keys = self.connections.all().values_list['link_type'].distinct()
conn = dict()
for key in link_keys:
conn[key]= [obj for obj in links if obj.type==key]
# conn = dict()
# for key in link_keys:
# conn[key]= [obj for obj in links if obj.type==key]
#add conn keys to main dict
return {
'title': self.title,
@ -61,8 +62,20 @@ PERSON_EVENT_CHOICES = (
class PersonEvent(models.Model):
person = models.ForeignKey(Person)
event = models.ForeignKey(Event):
typ = models.CharField(choices=PERSON_EVENT_CHOICES)
event = models.ForeignKey(Event)
typ = models.CharField(choices=PERSON_EVENT_CHOICES, max_length=128)
GROUP_EVENT_CHOICES = (
('venue', 'Venue'),
('performing', 'Performing'),
)
class GroupEvent(models.Model):
group = models.ForeignKey(TheatreGroup)
event = models.ForeignKey(Event)
typ = models.CharField(choices=GROUP_EVENT_CHOICES, max_length=128)
class Connection(models.Model):
link_type = models.CharField(max_length=255)

View File

@ -195,6 +195,7 @@ INSTALLED_APPS = (
'bestpractices',
'emailer',
'itfprofiles',
'events',
'pages',
'tagging',
'app',

View File