From 74eb21627eac9949ff205a662990f7e61f81627f Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 3 Sep 2012 19:25:16 +0530 Subject: [PATCH] add script relations --- itf/scriptbank/forms.py | 13 +++++++++++-- itf/scriptbank/models.py | 10 +++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/itf/scriptbank/forms.py b/itf/scriptbank/forms.py index 8a0d94f..b0cd390 100755 --- a/itf/scriptbank/forms.py +++ b/itf/scriptbank/forms.py @@ -1,19 +1,28 @@ import floppyforms as forms -from models import Script +from models import Script, ScriptScript from app.forms import * from itfprofiles.models import TheatreGroup +class RelatedScriptsForm(ItfForm): + script2 = forms.ModelChoiceField(Script.objects.all(), widget=AutocompleteAddWidget(model_class=Script)) + + class Meta: + model = ScriptScript + +ScriptScriptInline = itf_inlineformset_factory(Script, ScriptScript, fk_name='script1', form=RelatedScriptsForm, extra=1, title="Add / Edit Related Scripts", help_text="Select related scripts - like 'adaptation of', 'translation of'") + class ScriptForm(ItfForm): # no_characters = forms.IntegerField(widget=forms.NumberInput()) # no_of_women = forms.IntegerField(widget=forms.NumberInput()) # approx_duration = forms.IntegerField(widget=forms.NumberInput()) # contact = forms.EmailField(widget=forms.EmailInput()) + inlines = [ScriptScriptInline] theatre_group = forms.ModelChoiceField(TheatreGroup.objects.all(), widget=AutocompleteAddWidget(model_class=TheatreGroup)) class Meta: model = Script - exclude = ('added_by',) + exclude = ('added_by', 'related_scripts') widgets = { 'no_characters': forms.NumberInput, 'no_of_women': forms.NumberInput, diff --git a/itf/scriptbank/models.py b/itf/scriptbank/models.py index 42d9bc1..6fa19e3 100755 --- a/itf/scriptbank/models.py +++ b/itf/scriptbank/models.py @@ -43,6 +43,7 @@ class Script(ItfModel): fts_fields = ['title', 'synopsis', 'author'] fk_fields = ['license_adapt', 'license_perform'] theatre_group = models.ForeignKey(TheatreGroup, help_text="Theatre Group, if any") + related_scripts = models.ManyToManyField("Script", through="ScriptScript", related_name='related_script') # add_form = 'ScriptForm' #Meta @@ -75,8 +76,15 @@ class Script(ItfModel): 'license_perform': self.license_perform } +SCRIPT_RELATIONS = ( + ('adaptation', 'Adaptation Of'), + ('translation', 'Translation Of') +) - +class ScriptScript(models.Model): + script1 = models.ForeignKey(Script, related_name='related_from') + script2 = models.ForeignKey(Script, related_name='related_to') + relation_type = models.CharField(choices=SCRIPT_RELATIONS, max_length=64) class License(ItfModel):