from django import forms from .models import Work from interface.models import Project from interface.forms import BaseForm class WorkCreateForm(forms.ModelForm, BaseForm): class Meta: model = Work fields = [ "name", "composer", "edition", "code", "orchestration", "licence", "running_time", "notes", ] class PlaylistAddForm(forms.Form): work = forms.ModelChoiceField(queryset=Work.objects.all()) def __init__(self, instance, *args, **kwargs): super(PlaylistAddForm, self).__init__(*args, **kwargs) existing = [x[0] for x in instance.works.values_list("pk")] qs = Work.objects.filter(ensemble_id=instance.ensemble_id).exclude( id__in=existing ) self.fields["work"].queryset = qs self.instance = instance def save(self): self.instance.works.add(self.cleaned_data["work"]) class ProjectEnsembleChoiceField(forms.ModelChoiceField): def label_from_instance(self, obj): return f"{obj.ensemble.name} - {obj.name}" class ProjectSelectForm(BaseForm): project = ProjectEnsembleChoiceField(queryset=Project.objects.all()) class DocumentLinkForm(BaseForm): link = forms.URLField(help_text="Paste the direct link relevant to this storage") class DocumentBulkForm(BaseForm): folder_link = forms.URLField(help_text="Paste the folder link for this storage")