title: I'm having problems with wtforms selectfields when i use a POST with Flask
body: <p>I'm pretty new to wtforms and flask and was messing around with selectfields and got an error. The form itself works just fine without the selectfield but with it I get the following error:</p>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>....fields.py", line 386, in pre_validate
      for v, _ in self.choices: TypeError: 'NoneType' object is not iterable
  </code></pre>
  
  <p>I see the selectfield so it's being rendered. I suspect somehow the id is not being validated properly on POST and is returning none. Or it has something to do with my selectfield tuple being returned ? Also the ID field I'm using is pulled from GAE's ndb automatic key().id() which is rather long and obnoxious. It could be the id length being used for the selectfield is too long ? </p>
  
  <p>Googling hasn't provided much in terms of the exact problem so thought I'd post here. Relevant code below. If I'm missing something please let me know</p>
  
  <p><strong>views.py code:</strong></p>
  
  <pre><code>@app.route('/new/post', methods = ['GET', 'POST'])
  @login_required
  def new_post():
  
      form = PostForm()
      if form.validate_on_submit():
          post = Post(title = form.title.data,
                      content = form.content.data,
                      hometest = form.hometest.data,
                      author = users.get_current_user())
          post.put()
          flash('Post saved on database.')
          return redirect(url_for('list_posts'))
      form.hometest.choices = [ (h.key.id(),h.homename)for h in Home.query()]
  
      return render_template('new_post.html', form=form)
  </code></pre>
  
  <p><strong>myforms.py</strong>:</p>
  
  <pre><code>class PostForm(Form):
      title = wtf.TextField('Title', validators=[validators.Required()])
      content = wtf.TextAreaField('Content', validators=[validators.Required()])
      hometest = wtf.SelectField(u'Home Name List', coerce=int,validators=[validators.optional()])
  </code></pre>
  
  <p><strong>new_post.html:</strong></p>
  
  <pre><code>{% extends "base.html" %}
  
  {% block content %}
      &lt;h1 id=""&gt;Write a post&lt;/h1&gt;
      &lt;form action="{{ url_for('new_post') }}" method="post" accept-charset="utf-8"&gt;
          {{ form.csrf_token }}
          &lt;p&gt;
              &lt;label for="title"&gt;{{ form.title.label }}&lt;/label&gt;&lt;br /&gt;
              {{ form.title|safe }}&lt;br /&gt;
              {% if form.title.errors %}
              &lt;ul class="errors"&gt;
                  {% for error in form.title.errors %}
                  &lt;li&gt;{{ error }}&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
              {% endif %}
          &lt;/p&gt;
          &lt;p&gt;
              &lt;label for="title"&gt;{{form.hometest.label}}&lt;/label&gt;&lt;br/&gt;
              {{form.hometest}}
              {% if form.hometest.errors %}
          &lt;ul class="errors"&gt;
              {% for error in form.hometest.errors %}
              &lt;li&gt;{{ error }}&lt;/li&gt;
              {% endfor %}
          &lt;/ul&gt;
          {% endif %}
          &lt;/p&gt;
          &lt;p&gt;
              &lt;label for="title"&gt;{{ form.content.label }}&lt;/label&gt;&lt;br /&gt;
              {{ form.content|safe }}&lt;br /&gt;
  
              {% if form.content.errors %}
              &lt;ul class="errors"&gt;
                  {% for error in form.content.errors %}
                  &lt;li&gt;{{ error }}&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
              {% endif %}
          &lt;/p&gt;
          &lt;p&gt;&lt;input type="submit" value="Save post"/&gt;&lt;/p&gt;
      &lt;/form&gt;
  {% endblock %}
  </code></pre>