Setting queryset within forms.ModelChoiceField()
0 The queryset for the 'jurisdiction' field is set below in the initialization. The queryset is dependent on the id that is passed in, which comes from a specific link that a user clicks. As a result, I can't define a singular queryset within the forms.ModelChoiceField(), but it seems that django requires me to do this. class TaxForm (forms.ModelForm): #Will be used for state tax and other taxes jurisdiction = forms.ModelChoiceField(queryset=?????) class Meta: model = Tax exclude = ('user', 'taxtype',) def __init__(self, *args, **kwargs): self.taxtype = kwargs.pop('taxtype',None) super(TaxForm, self).__init__(*args, **kwargs) if int(self.taxtype) == 1: self.fields['jurisdiction'].choices = [(t.id, t) for t in State.objects.all()] elif int(self.taxtype) == 2: self.fields['jurisdiction'].choices = [(t.id, t) for t in Country.objects.all()] else: self.fields['jurisdiction'].choices = [(t.id, t) for t in