title: How to dynamically set the queryset of a models.ModelChoiceField on a forms.Form subclass
body: <p>The constructor for <code>forms.ModelChoiceField</code> requires a queryset. I do not know the queryset until the request happens. Distilled:</p>
  
  <pre><code># models.py
  class Bar(models.model):
      text = models.TextField()
  
  class Foo(models.Model):
      name = models.CharField()
      bar = models.ForeignKey(Bar)
  
  # forms.py
  class FooForm(forms.Form):
      name = forms.CharField()
      text = forms.CharField(widget=forms.TextArea)
  
      bar = forms.ModelChoiceField(queryset='??????')
  </code></pre>
  
  <p>What I am currently doing:</p>
  
  <pre><code># forms.py
  
  def get_foo_form_class(bars_queryset):
      class FooForm(forms.Form):
          name = forms.CharField()
          text = forms.CharField(widget=forms.TextArea)
  
          bar = forms.ModelChoiceField(queryset=bars_queryset)
  
      return FooForm
  </code></pre>
  
  <p>I can then call it in the view using arguments parsed out of the url with a urlconf to construct the queryset and get the class. This feels like the wrong way to do it. Is there an established way to do this in django?</p>