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 


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -