title: Make WTForms set field label from database model
body: <p>I have three tables: <em>components</em>, <em>attributes</em> and <em>attribute_values</em>. Each component can have many <em>attribute_values</em>. Each <em>attribute_value</em> belongs to one <em>attribute</em>. Yeah, it's the dreaded EAV pattern...</p>
  
  <p>I have created these two forms:</p>
  
  <pre><code>class AttributeValueForm(Form):
      attribute = HiddenField()
      value = StringField('Value')
  
  class ComponentForm(Form):
      ... non-related fields left out ...
      attribute_values = FieldList(FormField(AttributeValueForm))
  </code></pre>
  
  <p>These are the SQLAlchemy models:</p>
  
  <pre><code>class Component(db.Model):
      __tablename__ = 'components'
      id = db.Column(db.Integer, primary_key=True)
      ... non-related columns left out ...
  
  class AttributeValue(db.Model):
      __tablename__ = 'attribute_values'
      id = db.Column(db.Integer, primary_key=True)
      value = db.Column(db.String)
  
      attribute_id = db.Column(db.Integer, db.ForeignKey('attributes.id'))
      attribute = db.relationship('Attribute', backref='attribute_values'))
  
      component_id = db.Column(db.Integer, db.ForeignKey('components.id'))
      component = db.relationship('Component', backref='attribute_values'))
  
  def Attribute(db.Model):
      __tablename__ = 'attributes'
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(60))
  </code></pre>
  
  <p>My problem is that I would like to see the <em>name</em> of the attribute as the label of the value field (replacing 'Value'). I've been trying to wrap my head around how WTForms work internally, but I can't see any obvious way to do this.</p>
  
  <p>Any hints appreciated. I could even do with a hack that just renders a custom label, if I could only get hold of the AttributeValue object while rendering the value field.</p>