title: Populate a WTForms form object with a datetime.date
body: <p>I'm cooking up a crud interface for an object representing a bill, as in the water bill, the electric bill, etc.</p>
  
  <p>I'm using sqlalchemy to handle the data, wtforms to handle the forms, and flask to serve it.  </p>
  
  <p>Here's what my route looks like that serves the form for editing an existing bill:</p>
  
  <pre><code>@app.route('/edit_bill/&lt;int:bill_id&gt;', methods = ['GET'])
  def edit_bill(bill_id):
      s = Session()
      bill = s.query(Bill).filter_by(id=bill_id).first()
      form = BillForm(obj=Bill)
      return render_template('edit_bill.html', form = form)
  </code></pre>
  
  <p>Using wtforms, I pass the bill object to the BillForm constructor, ensuring that the data representing the bill to be edited it populated to the form. </p>
  
  <p>This is where it chokes.  Here's the exception:</p>
  
  <pre><code>AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with Bill.date_due has an attribute 'strftime'
  </code></pre>
  
  <p>Now, I've dipped into the python shell and queried up a bill to make sure that date_due has a <code>datetime.date</code> object on it, which is does.  I use Jinja to build my front end, so I've looked into creating a template filter, but I don't know how that would work with wtforms, and it looks like sqlalchemy is the one choking anyway.  </p>
  
  <p>So what it do?  I'm pretty confident I just need to figure out how to turn that <code>datetime.date</code> object into a string, but I'm not sure how to go about that.  </p>
  
  <p>Halp. Thanks!</p>
  
  <p><strong>Edit:  Here's the BillForm class:</strong></p>
  
  <pre><code>class BillForm(Form):
      id                  = HiddenField()
      name                = TextField(u'Name:', [validators.required()])
      pay_to              = TextField(u'Pay To:',[validators.required()])
      date_due            = DateField(u'Date Due:',[validators.required()])
      amount_due          = IntegerField(u'Amount Due:', [validators.required()])
      date_late           = DateField(u'Late After:',[validators.required()])
      amount_late         = IntegerField(u'Late Amount:', [validators.required()])
      date_termination    = DateField(u'Termination Date:',[validators.required()])
  </code></pre>
  
  <p><strong>And mapping class, too:</strong></p>
  
  <pre><code>class Bill(Base):
      __tablename__ = 'bills'
  
      id = Column(Integer, primary_key=True)
      name = Column(String)
      pay_to = Column(String)
      amount_due = Column(Integer)
      date_due = Column(Date)
      amount_late = Column(Integer)
      date_late = Column(Date)
      date_termination = Column(Date)
  
      def __init__(self, name, pay_to, amount_due, date_due, amount_late, date_late, date_termination):
          self.name               = name
          self.pay_to             = pay_to
          self.amount_due         = amount_due
          self.date_due           = date_due
          self.amount_late        = amount_late
          self.date_late          = date_late
          self.date_termination   = date_termination
  
      def __repr__(self):
          return "&lt;Bill ('%s', '%s', '%s', '%s')&gt;" % (self.name, self.pay_to, self.amount_due, self.date_due)
  </code></pre>