forked from rc/aircox
aircox/forms/episode: limit available sounds
This commit is contained in:
parent
9a58fba0fd
commit
1363d22e89
|
@ -14,8 +14,18 @@ class EpisodeForm(ChildPageForm):
|
|||
fields = ChildPageForm.Meta.fields
|
||||
|
||||
|
||||
class EpisodeSoundForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
if "instance" in kwargs:
|
||||
"""Limit available sounds."""
|
||||
episode_sounds = kwargs["instance"].episode.episodesound_set.all()
|
||||
self.fields["sound"].queryset = models.Sound.objects.filter(id__in=[x.sound.id for x in episode_sounds])
|
||||
|
||||
|
||||
EpisodeSoundFormSet = modelformset_factory(
|
||||
models.EpisodeSound,
|
||||
form=EpisodeSoundForm,
|
||||
fields=(
|
||||
"position",
|
||||
"episode",
|
||||
|
|
Loading…
Reference in New Issue
Block a user