您必须在modelform的
__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)
form = DogImageForm(user=request.user)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)