From the WTForms-Alchemy advanced section:
In order to make WTForms-Alchemy work with Flask-WTF you need the following snippet:
from flask.ext.wtf import Form from wtforms_alchemy import model_form_factory ModelForm = model_form_factory(Form)
The you can use the ModelForm just like before:
class UserForm(ModelForm): class Meta: model = User
This does rely on User
having a .query
object; e.g. your User
model must be derived from db.Model
. If it doesn't then you need to define get_session
method on the form:
class UserForm(ModelForm):
class Meta:
model = User
def get_session(self):
return db.session