title: SQL Alchemy/ Flask / WTF Forms set a default value for a queryselectfield
body: <p>I want to set a default value for my queryselectfield. My code looks like this: </p>
  
  <p>Template:</p>
  
  <pre><code>{% import "bootstrap/utils.html" as utils %}
  {% import "bootstrap/wtf.html" as wtf %}
  {% extends "base.html" %}
  {% block title %}Request{% endblock %}
  {% block body %}
  &lt;div class="content-section"&gt;
  ...
  {{ form.country(class_="selectformfield") }
  ...
  </code></pre>
  
  <p>Route:</p>
  
  <pre><code>@requests.route('/request/add', methods=['GET', 'POST'])
  @login_required
  def add_request():
  
  check_admin()
  
  add_request = True
  
  form = RequestForm()
  if form.validate_on_submit():
      ...
      Country = form.hostname.data
      ...
  
      request = Request(...country=country, ...)
  
      try:
          # add request to the database
          db.session.add(request)
          db.session.commit()
          flash('You have successfully added a new request.')
      except:
          # in case request name already exists
          flash('Error: request already exists.')
  
      # redirect to the request page
      return redirect(url_for('requests.show_request', id=request.id))
  
  # load request template
  return render_template('requests/add_request.html', add_request=add_request,
                         form=form, title='Add new Request')
  </code></pre>
  
  <p>Form:</p>
  
  <pre><code>class RequestForm(FlaskForm):
  ...
  country = QuerySelectField(query_factory=lambda: Country.query.all(), get_label="name")
  ...
  </code></pre>
  
  <p>I already tried it like this, but it didn't work. </p>
  
  <pre><code>default_country = query_factory=lambda: Country.query.filter(Country.id == '1')
  country = QuerySelectField(query_factory=lambda: Country.query.all(), get_label="name", default=default_country)
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/21579373/sqlalchemy-wtforms-set-default-selected-value-for-queryselectfield">SQLAlchemy/WTForms: set default selected value for QuerySelectField</a>
  I also already read this post here with a simmilar problem, but the solution doesn't work for me. 
  Can annyone help me?</p>