title: WTForms dynamic forms with configurable validation
body: <p>I'm building a system which allows admin users to add "questions" to the database.  Each type of question has a WTForms object associated with it.  To display a page, I loop over all questions and generate a form consisting of form fields for each question.</p>
  
  <pre><code>class TextQuestionForm(Form):
    value = TextField("Value", validators=[])
  
  class Question(db.Model):
    # sqlAlchemy model using single table inheritance
    def field_name(self):
      return "question_%s" % self.id
  
  class TextQuestion(Question):
    form = TextQuestionForm
  
  
  def get_form(page_id):
    questions = Question.query.filter(Question.page_id == page_id).all()
  
    class F(Form):
      pass
  
    for q in questions:
      setattr(F, q.field_name(), FormField(q.form))
  
    return F()
  </code></pre>
  
  <p>This works well for simple cases where all validation is the same for a given question type, but I need to provide configurable validation options for each instance of <code>Question</code>, for example imagine if my Question model was extended:</p>
  
  <pre><code>class Question(db.Model):
    # ... other fields
    min_length = db.Column(db.Integer, nullable=True)
    max_length = db.Column(db.Integer, nullable=True)
  </code></pre>
  
  <p>What would be the appropriate way to get a WTForms length validator on to the <code>value</code> field within my Form field, given that min/max lengths would be different (or missing) for each question?</p>