X-Git-Url: https://git.0d.be/?p=django-panik-combo.git;a=blobdiff_plain;f=panikombo%2Fforms.py;fp=panikombo%2Fforms.py;h=ed3991a8dd4b858bfd8c2eafa561403b990ff992;hp=57f0329ff1229f04573008fd4b777fb1b52474c7;hb=e960f6c41cc47f908e5e685e9f8be029cce3d8c3;hpb=ed37c5bdd689bba07688b86822025a50cbcb1f0a diff --git a/panikombo/forms.py b/panikombo/forms.py index 57f0329..ed3991a 100644 --- a/panikombo/forms.py +++ b/panikombo/forms.py @@ -1,10 +1,10 @@ from django import forms from django_select2.widgets import HeavySelect2Widget, convert_to_js_string_arr -from emissions.models import SoundFile +from emissions.models import SoundFile, Episode -from .models import SoundCell -from .views import soundfiles +from .models import SoundCell, EpisodeCell +from .views import soundfiles, episodes class SoundFileWidget(HeavySelect2Widget): def render_texts(self, selected_choices, choices): @@ -25,3 +25,22 @@ class SoundCellForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(SoundCellForm, self).__init__(*args, **kwargs) self.fields['soundfile'].widget = SoundFileWidget(data_view=soundfiles) + + +class EpisodeWidget(HeavySelect2Widget): + def render_texts(self, selected_choices, choices): + queryset = Episode.objects.filter(id__in=selected_choices) + def fmt(episode): + return '%s - %s' % (episode.emission.title, episode.title) + texts = [fmt(episode) for episode in queryset.select_related()] + return convert_to_js_string_arr(texts) + + +class EpisodeCellForm(forms.ModelForm): + class Meta: + model = EpisodeCell + fields = ('episode', ) + + def __init__(self, *args, **kwargs): + super(EpisodeCellForm, self).__init__(*args, **kwargs) + self.fields['episode'].widget = EpisodeWidget(data_view=episodes)