title: How to create a filtered dropdown using Django forms?
body: <p>I've got this model :</p>
  
  <pre><code>class QuestionInstance(models.Model):
      questionsSet = models.ForeignKey(QuestionsSet)
      question     = models.ForeignKey(Question)
      parent       =  models.ForeignKey('self',null=True,blank=True)
      optional     = models.BooleanField(default=False)
  </code></pre>
  
  <p>I'd like to create a dropdown, which user could choose one QuestionInstance.
  It has to be filtered with questionsSet.</p>
  
  <p>I've tested using a modelform like this, but it's not working :</p>
  
  <p>(based on this <a href="https://stackoverflow.com/questions/3010489/how-do-i-filter-values-in-a-django-form-using-modelform/3013050">How do I filter values in a Django form using ModelForm?</a>)</p>
  
  <pre><code>class FormQuestionSelect(ModelForm):
      instanceList = forms.ChoiceField(choices=[(questionInstance.id, questionInstance.question) for questionInstance in QuestionInstance.objects.all()])
  
      class Meta:
          model = QuestionInstance
          fields = ('instanceList', )
          widgets = {
              'instanceList': Select(attrs={'class': 'select'}),
          }
  
      def __init__(self, questionsSet=None, **kwargs):
          super(FormQuestionSelect, self).__init__(**kwargs)
          if questionsSet:
              #Tested many code here to filter, None of them worked :(
              #Is that possible to create instanceList there ?                        
  </code></pre>
  
  <p>I'm not sure using a modelform is a good idea for this kind of purpose.</p>
  
  <p>A modelform is great when create or update a model instance.
  When using specific forms, like in this case, I'm using a custom form in template :</p>
  
  <p>View</p>
  
  <pre><code>questionInstanceList = QuestionInstance.objects.filter(questionsSet=questionsSet)
  </code></pre>
  
  <p>Template</p>
  
  <pre><code>&lt;select name="questionInstanceSelect"&gt;
      {% for instance in questionInstanceList %}
          &lt;option value="{{ instance.id }}"&gt;{{ instance.question.text }}&lt;/option&gt;
      {% endfor %}
  &lt;/select&gt;
  </code></pre>
  
  <p>and process them this way :</p>
  
  <pre><code>instanceList = request.POST.get('questionInstanceSelect')
  </code></pre>
  
  <p>I'm quite sure there's a proper way.</p>