title: WTForm: how do I tell Form to use a custom method for one particular attribute?
body: <p>I have the following definitions: </p>
  
  <pre><code>class ProduceType(ndb.Model):
    crop = ndb.StringProperty()
    variety = ndb.StringProperty()
  
  class OrderEntry(ndb.Model):
    producetype = ndb.KeyProperty(kind=ProduceType, required=True)
    quantity = ndb.IntegerProperty(required=True)
  </code></pre>
  
  <p>I created the following WTForm:</p>
  
  <pre><code>class OrderEntryForm(Form):
    quantity = IntegerField('Quantity',
                            [validators.Required(), validators.NumberRange(min=1)])
    # we will be dynamically adding choices
    producetype = SelectField('Produce',
                              [validators.Required()],
                              choices=[])
  </code></pre>
  
  <p>This is what I am doing in my tests:</p>
  
  <pre><code>def setUp(self):
    self.pt1 = ProduceType(crop='Choi', variety='Bok')
    self.pt2 = ProduceType(crop='Cress', variety='True')
    self.pt1.put()
    self.pt2.put()
  
  def test_order_entry(self):
    oe = OrderEntry(producetype=self.pt1.key, quantity=20)
    oef = OrderEntryForm(obj=oe)
    oef.producetype.choices = [
        (self.pt1.key.id(), self.pt1.name()),
        (self.pt2.key.id(), self.pt2.name())
    ]
    print oef.producetype
  </code></pre>
  
  <p>And this is what's being printed:</p>
  
  <pre><code>&lt;select id="producetype" name="producetype"&gt;&lt;option value="1"&gt;Choi - Bok&lt;/option&gt;&lt;option value="2"&gt;Cress - True&lt;/option&gt;&lt;/select&gt;
  </code></pre>
  
  <p><strong>Problem:</strong>
  I am trying to render the form for my users to edit. </p>
  
  <p>So if an OrderEntry in my database looks likes: </p>
  
  <pre><code>order_entry = { producetype: self.pt1.key, quantity: 5 } 
  </code></pre>
  
  <p>I would expect WTForms to be rendering something like:</p>
  
  <pre><code>&lt;select id="producetype" name="producetype"&gt;
    &lt;option value="1" selected&gt;Choi - Bok&lt;/option&gt;
    &lt;option value="2"&gt;Cress - True&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>However, right now I cannot get WTForm to render the <strong>selected</strong> properly. The select being rendered is currently empty. </p>
  
  <p>How do I get WTForm to render <strong>selected</strong> correctly? </p>
  
  <p><strong>NOTE</strong>:</p>
  
  <p>During form population, i.e. <code>oef = OrderEntryForm(obj=oe)</code>, if WTForm tries to access obj.producetype, that will give you a <code>ndb.key</code>. As you can see, the first member of the oef.producetype.choices tuple is of <code>ndb.key.id()</code> as opposed to <code>ndb.key</code></p>