added ProductionForm, ScriptForm, both working

This commit is contained in:
Sanj 2012-07-27 14:17:42 +05:30
parent 8137abad92
commit 8ec6b0870c
5 changed files with 27 additions and 7 deletions

View File

@ -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)

View File

@ -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',)

View File

@ -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)

View File

@ -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',)

View File

@ -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")