From 8ec6b0870cd3f89c5d1debb6bdba206e46528501 Mon Sep 17 00:00:00 2001 From: Sanj Date: Fri, 27 Jul 2012 14:17:42 +0530 Subject: [PATCH] added ProductionForm, ScriptForm, both working --- itf/app/forms.py | 5 +++-- itf/itfprofiles/forms.py | 11 +++++++++++ itf/itfprofiles/models.py | 6 ++++-- itf/scriptbank/forms.py | 8 ++++++-- itf/scriptbank/models.py | 4 +++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/itf/app/forms.py b/itf/app/forms.py index ecbe486..3addc4a 100644 --- a/itf/app/forms.py +++ b/itf/app/forms.py @@ -3,7 +3,8 @@ from django.contrib.contenttypes.models import ContentType from crispy_forms.helper import FormHelper class ItfForm(forms.ModelForm): - + inlines = [] + def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.form_tag = False @@ -25,7 +26,7 @@ class AutocompleteAddWidget(forms.Select): model_class should be the model class that this is an add / autocomplete widget for ''' template_name = 'formwidgets/select2.html' - + def __init__(self, *args, **kwargs): model_class = kwargs.pop('model_class') self.ctype = ContentType.objects.get_for_model(model_class) diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index 5170e57..9139534 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -155,3 +155,14 @@ class TheatreGroupForm(ItfForm): class Meta: model = TheatreGroup exclude = ('added_by', 'locations',) + + + +class ProductionForm(ItfForm): + inlines = [] + director = forms.ModelChoiceField(Person.objects.all(), widget=AutocompleteAddWidget(model_class=Person)) + playwright = forms.ModelChoiceField(Person.objects.all(), widget=AutocompleteAddWidget(model_class=Person)) + group = forms.ModelChoiceField(TheatreGroup.objects.all(), widget=AutocompleteAddWidget(model_class=TheatreGroup)) + class Meta: + model = Production + exclude = ('added_by',) diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index e3c737f..f395040 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -6,6 +6,7 @@ from django.contrib.localflavor.in_.forms import INZipCodeField #from ox.django.fields import DictField from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic +from scriptbank.models import Script GENDER_CHOICES = ( ('M', 'Male'), @@ -203,9 +204,10 @@ class Play(ItfModel): class Production(ItfModel): # user = models.ForeignKey(User) fts_fields = ['name', 'group__name'] - form_names = ['PopupProductionForm'] + form_names = ['ProductionForm', 'PopupProductionForm'] + main_form = 'ProductionForm' added_by = models.ForeignKey(User) - play = models.ForeignKey("Play", null=True, blank=True) + script = models.ForeignKey(Script, blank=True, null=True) name = models.CharField(max_length=255, db_index=True) synopsis = models.TextField(blank=True) language = models.ForeignKey("Language", blank=True, null=True) diff --git a/itf/scriptbank/forms.py b/itf/scriptbank/forms.py index 038d15b..28f5a2b 100755 --- a/itf/scriptbank/forms.py +++ b/itf/scriptbank/forms.py @@ -1,6 +1,10 @@ -from django.forms import ModelForm +import floppyforms as forms from models import Script +from app.forms import * + + +class ScriptForm(ItfForm): -class ScriptForm(ModelForm): class Meta: model = Script + exclude = ('added_by',) diff --git a/itf/scriptbank/models.py b/itf/scriptbank/models.py index d63aabd..1ccfd26 100755 --- a/itf/scriptbank/models.py +++ b/itf/scriptbank/models.py @@ -22,7 +22,9 @@ LANGUAGE_CHOICES = ( ) class Script(ItfModel): - user = models.ForeignKey(User) + added_by = models.ForeignKey(User) + form_names = ['ScriptForm'] + main_form = 'ScriptForm' title = models.CharField(max_length=255) synopsis = models.TextField(blank=True) no_characters = models.IntegerField(blank=True, null=True, help_text="Approximate number of characters")