title: Pass form data directly to SQLalchemy object?
body: <p>I am using Flask with WTForms and SQLAlchemy. I currently have this set up:</p>
  
  <p>A SQLAlchemy class:</p>
  
  <pre><code>class User(Base):
      __tablename__ = 'user'
      name = db.Column(db.String)
      last_name = db.Column(db.String)
  
      __init__(name, last_name):
          self.name = name
          self.last_name = last_name
  </code></pre>
  
  <p>The corresponding form:</p>
  
  <pre><code>class CreateUserForm(Form):
      name = StringField('Name')
      last_name = StringField('Last name')
  </code></pre>
  
  <p>And the route:</p>
  
  <pre><code>@user.route('/', methods=['POST'])
  def create():
      form = CreateUserForm(request.form)
  
      if form.validate():
          user = User(form.name.data, form.last_name.data)
          ...
  </code></pre>
  
  <p>This is just a simplified example but what I wonder is if I could just in some way just pass the form variable to the User constructor and all the way to the User class in SQLAlchemy? Since there will be the same fields in the form as in the constructor as in the user database table it would be nice.</p>
  
  <p>I want my route to look like this instead:</p>
  
  <pre><code>@user.route('/', methods=['POST'])
  def create():
      form = CreateUserForm(request.form)
  
      if form.validate():
          user = User(form)
          ...
  </code></pre>
  
  <p>So I don't have to deal with form.name and form.last_name in each part.</p>