7👍
✅
You would have to do it in the modelform’s __init__
class DogImageForm(ModelForm):
dogs = forms.ModelChoiceField(queryset=Dog.objects.none())
class Meta:
model = ResultsUpload
def __init__(self, user, *args, **kwargs):
super(DogImageForm, self).__init__(*args, **kwargs)
self.fields['dogs'].queryset = Dog.objects.filter(user=user)
and during the initialization of the form,
form = DogImageForm(user=request.user)
Source:stackexchange.com