title: Passing Parameter for Queryset to Django Form
body: <p>I am using a django (2.1) ModelMultipleChoice field for a form. I am trying to modify the queryset based on the slug in the URL. I am pretty certain I am missing something stupid.</p>
  
  <p>The Form:</p>
  
  <pre><code>class SubdomainForm(forms.Form):
      # TODO Get the value slug from init
      slug = "camp" # Works well if value of slug set here.
      q = Feature2Subdomain.objects.all().select_related().filter(subdomain__slug=slug)
      choices = forms.ModelMultipleChoiceField(
          queryset = q,
          widget = forms.CheckboxSelectMultiple,
      )
  
  def __init__(self, *args, **kwargs):
      slug = kwargs.pop('slug', None) # Correctly obtains slug from url
      super(SubdomainForm, self).__init__(*args, **kwargs)
  </code></pre>
  
  <p>The View:</p>
  
  <pre><code>class SubdomainDetailView(FormView):
      template_name = "guide/subdomain-detail.html"
      form_class = SubdomainForm
  
      def get_form_kwargs(self, form_class=SubdomainForm):
          s = dict(slug = self.kwargs['slug'])
          return s
  </code></pre>
  
  <p>URLS.py</p>
  
  <pre><code>urlpatterns = [
      path('subdomain/&lt;slug:slug&gt;/',
           SubdomainDetailView.as_view(),
           name="subdomain-detail"
      ),
      .....
  </code></pre>
  
  <p>Obviously, the idea is that the slug from the URL is used to modify the queryset. (in the example the value of the slug is "camp"</p>
  
  <p>I can obtain the value of the slug in the <strong>init</strong> method for the form, and can call super() to instantiate the form. However, I can't figure out how to access the value in the "choices" line of the form. If I hard code the value of slug="camp" I can get the whole thing to work properly.</p>
  
  <p>I've been working on this for a couple of days and have exhausted all the examples in SO and on google.</p>
  
  <p>I tried moving the "choices" assignment into the <strong>init</strong> method and using </p>
  
  <pre><code> self.choices = forms.ModelMultipleChoiceField(
          queryset = Feature2Subdomain.objects.all().select_related().filter(subdomain__slug=slug)
          widget = forms.CheckboxSelectMultiple,
      )
  </code></pre>
  
  <p>But this is not then displaying the correct response (it returns an empty form)</p>
  
  <p>Also tried assigning the queryset in the <strong>init</strong> method like this.</p>
  
  <pre><code>class SubdomainForm(forms.Form):
      choices = forms.ModelMultipleChoiceField(
          widget = forms.CheckboxSelectMultiple,
      )
  
      def __init__(self, *args, **kwargs):
          slug = kwargs.pop('slug', None) # Correctly obtains slug from url
          self.queryset = Feature2Subdomain.objects.all().select_related().filter(subdomain__slug=slug)
  
          super(SubdomainForm, self).__init__(*args, **kwargs) 
  </code></pre>
  
  <p>I then get the error: 
  TypeError: <strong>init</strong>() missing 1 required positional argument: 'queryset'</p>
  
  <p>Feeling quite lost on where to go next.</p>
  
  <p>Any help would be appreciate.</p>