python - Many-to-Many relation fields with WTForms-Alchemy? -
on documentation page, there examples of how use wtforms-alchemy one-to-one , one-to-many relations. have tables use many-to-many , can't seem figure out how render form fields. code below reference.
from flask.ext.wtf import form wtforms import form form2 wtforms_alchemy import model_form_factory, modelform, modelfieldlist wtforms.fields import formfield app.models.bookmodel import book app.models.submodels import booktypeform basemodelform = model_form_factory(form) basesubmodelform = model_form_factory(form2) class modelform(basemodelform): @classmethod def get_session(self): return db.session class submodelform(basesubmodelform): @classmethod def get_session(self): return db.session class booktypeform(submodelform): class meta: model = booktype = ['name'] class bookform(modelform): class meta: model = book book_type = modelfieldlist(formfield(booktypeform))
this the book_type field , model
class booktype(db.model): __tablename__ = 'book_type' id = db.column(db.integer, autoincrement=true, primary_key=true) name = db.column( choicetype(book_types, impl=db.unicode(16)) ) def __repr__(self): return "<booktype (name='%s')>" % self.name