title: Dynamically Populate WTForm SelectField with sqlAlchemy query
body: <p>I'm trying to dynamically populate options in a drop down with data from a column in my postgreSQL database. When I try to load my form I get: TypeError: 'NoneType' object is not iterable. Any help will be greatly appreciated.     </p>
  
  <pre><code>  File "/usr/lib/python2.7/site-packages/wtforms/widgets/core.py", line 323, in __call__
      for val, label, selected in field.iter_choices():
    File "/usr/lib/python2.7/site-packages/wtforms/fields/core.py", line 454, in iter_choices
      for value, label in self.choices:
  TypeError: 'NoneType' object is not iterable
  </code></pre>
  
  <p>Model.py</p>
  
  <pre><code>class ReqCriterion(Base):
      __tablename__ = 'req_criteria'
  
      criteria_id = Column(Integer, primary_key=True, server_default=text("nextval('req_criteria_criteria_id_seq'::regclass)"))
      req_id = Column(Integer, nullable=False)
      req_name = Column(Text)
      coi_id = Column(Integer, nullable=False)
      coi_name = Column(Text, nullable=False)
      criteria = Column(Text)
  
      def __init__(self, criteria, req_name, coi_id, coi_name, req_id):
          self.criteria = criteria
          self.req_id = req_id
          self.req_name = req_name
          self.coi_id = coi_id
          self.coi_name = coi_name
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class NewProjForm(Form):
      pj_name = StringField('Project Name', validators=[InputRequired(), Length(min=1, max=1000)])
      pj_desc = TextAreaField('Project Description', validators=[InputRequired(), Length(min=1, max=3000)])
      coi_name = SelectField('COI:', validators=[InputRequired()])
      pj_poc_first = StringField('POC First Name', validators=[InputRequired(), Length(min=1, max=500)])
      pj_poc_last = StringField('POC Last Name', validators=[InputRequired(), Length(min=1, max=500)])
  </code></pre>
  
  <p>app.py</p>
  
  <pre><code>@app.route('/addProjForm', methods=['GET','POST'])
  def addProjForm():
          newProj = NewProjForm(request.form)
          newProj.coi_name.choices = db.session.query(ReqCriterion).filter(coi_name)
          if request.method == 'POST' and newProj.validate():
              addProj = Project(request.form['pj_name'], request.form['pj_desc'], request.form['coi_name'], request.form['pj_poc_first'], request.form['pj_poc_last'])
              db.session.add(addProj)
              db.session.commit()
              return redirect(url_for('project_conf', addProj=addProj))
  </code></pre>