class WorkForm(forms.Form):
road = forms.ModelChoiceField(
label='Выберите объект',
queryset=Roads.objects.filter(contractor=request.user.id))
name 'request' is not defined
__init__
, куда параметром отдавайте нужное.class WorkForm(forms.Form)
road = forms.ModelChoicField(label='', queryset=Road.objects.none())
def __init__(self, *args, **kwargs):
user_id = kwargs.pop('user_id', None)
super(WorkForm, self).__init__(*args, **kwargs)
self.fields['road'].queryset = Roads.objects.filter(contractor=user_id)