title: Dynamic choices WTForms Flask SelectField
body: <p>I'm trying to pass userID variable to WTForms with FlaskForms. First I'll show code that works fine and then what I need to modify(that the part I don't know how). I'm adding new Name associated with some group. </p>
  
  <p><strong>FlaskForm model:</strong></p>
  
  <pre><code>class AddName(FlaskForm):
      name =StringField('Device name', validators=[InputRequired(),Length(min=4, max=30)])
      groupID = SelectField('Payload Type', choices=[(1,"Group1"),(2,"Group2")], validators=[InputRequired])
  </code></pre>
  
  <p><strong>View model:</strong></p>
  
  <pre><code>@app.route('/dashboard/addname', methods=['GET', 'POST'])
  def addname():
      form=AddName()
      if form.validate_on_submit():
          name=Name(form.name.data,form.groupID.data)
          db.session.add(name)
          db.session.commit()
          return "New name added"
  </code></pre>
  
  <p><strong>Template:</strong></p>
  
  <pre><code>              &lt;form method="POST" action="/dashboard/addname"&gt;
                    &lt;h2&gt;Add name&lt;/h2&gt;
                    {{ form.hidden_tag() }}
                    {{ wtf.form_field(form.name) }}
                    {{ wtf.form_field(form.groupID) }}
                    &lt;button type="submit"&gt;Add name&lt;/button&gt;
                &lt;/form&gt;
  </code></pre>
  
  <p>I see correct list in dropdown, and on submit gives me correct numbers.</p>
  
  <p><strong>Task:</strong> I need to pass different list based on <strong>current_user.userID</strong>.
  I'm forming list using SQLAlchemy, by making query from table from DB, so My <strong>Flask view is:</strong></p>
  
  <pre><code>@app.route('/dashboard/addname', methods=['GET', 'POST'])
  def addname():
      available_groups=db.session.query(Groups).filter(Groups.userID == currend_user.userID).all()
      #Now forming the list of tuples, so it's ok for SelectField
      groups_list=[(i.groupID, i.groupName) for i in available_groups]
      form=AddName()
      if form.validate_on_submit():
          name=Name(form.name.data,form.groupID.data)
          db.session.add(name)
          db.session.commit()
          return "New name added"
  </code></pre>
  
  <ol>
  <li>How can i pass my <strong>groups_list</strong> to the form? I tried to implement forming procedure in the FlaskForm model, but it doesn't see current_user object</li>
  <li>Do I need to transform groupID to <em>string</em> and then back to <em>int</em> when I need to pass it to the SelectField like tuples?</li>
  </ol>