from django.forms import ModelForm from guardian.shortcuts import get_objects_for_user from . import models class RestreamFilteredStreamForm(ModelForm): class Meta: model = models.Restream fields = ['name', 'stream', 'target', 'format', 'active'] def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) super().__init__(*args, **kwargs) # limit the stream selection to user-accessible streams self.fields['stream'].queryset = get_objects_for_user(user, 'config.view_stream') class PullFilteredStreamForm(ModelForm): class Meta: model = models.Pull fields = ['name', 'stream', 'source', 'active'] def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) super().__init__(*args, **kwargs) # limit the stream selection to user-accessible streams self.fields['stream'].queryset = get_objects_for_user(user, 'config.view_stream')