title: Change default field value for editing QuerySelectField data
body: <p>I have a Flask form that uses <code>QuerySelectField</code> to generate a field based on a related database table. I use the same form for "add" and "edit" actions. However, I cannot figure out how to change the value of this field's "default" for the edit, so that it shows the value of the existing record. In fact, when editing, the default isn't shown at all; there's no "selected" in the form at all.</p>
  
  <p>This is a database of <code>Wine</code>, with a related table <code>Size</code> that contains:</p>
  
  <pre><code>+---------+--------+-----+
  | size_id | size   | seq |
  +---------+--------+-----+
  |       1 | 750 ml |   3 |
  |       2 | 375 ml |   1 |
  |       3 | 500 ml |   2 |
  |       4 | magnum |   4 |
  +---------+--------+-----+
  </code></pre>
  
  <p>My form definition (showing only the "size" stuff) is:</p>
  
  <pre><code>class WineForm(FlaskForm):
  
      def size_choices():
          return Size.query.order_by(Size.seq).all()
  
      def get_size_default():
          return Size.query.filter(Size.size == '750 ml').one()
  
      size = QuerySelectField('Size',
                              validators=[Required()],
                              query_factory=size_choices,
                              default=get_size_default)
  </code></pre>
  
  <p>My "add" view, in relevant part, is simply</p>
  
  <pre><code>def wine_add():
      form=WineForm(request.form)
      # etc.
  </code></pre>
  
  <p>And this correctly displays a select field with "750 ml" being the default value, as the third entry in a list of four.</p>
  
  <p>However, my "edit" view always defaults to "375 ml", with no "selected" value. The "edit" view includes:</p>
  
  <pre><code>def wine_edit(id):
      record = Wine.query.filter(Wine.id == id).one_or_none()
  
      if record is None:
          flash('Record does not exist')
          return redirect(url_for('index'))
      form = WineForm(obj=record)
  </code></pre>
  
  <p>This displays "375 ml" no matter what. I have tried setting values for <code>form.size.data</code> and for <code>form.size.default</code>, consisting of string values or integer ID's or database query objects; nothing works.</p>
  
  <p>By way of comparison, I have another <code>QuerySelectField</code> (not shown here) for <code>country</code>; this does not have a default set (the database order is fine), and this field does correctly display with the value from the existing record. It appears to be the inclusion of the "default" in the definition of the <code>size</code> field that causes this issue, but I don't know what it should be.</p>
  
  <p>I've tried a lot of things to debug this, with no joy, and would be grateful for any suggestions. Thanks.</p>