add script relations

This commit is contained in:
Sanj 2012-09-03 19:25:16 +05:30
parent 607285beac
commit 74eb21627e
2 changed files with 20 additions and 3 deletions

View File

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

View File

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