我正在使用sqlalchemy和wtforms在龙卷风中构建一个应用程序.我有两个模特委员会和会员有多对多的关系.我在使用sqlalchemy模型填充表单时遇到问题.
我的模特看起来像这样
class Committee(Base):
__tablename__ = 'committee'
id_ = Column(Integer, primary_key=True)
name = Column(String)
class Member(Base):
__tablename__ = 'member'
id_ = Column(Integer, primary_key=True)
name = Column(String)
phone = Column(String)
committee = relationship("Committee",
secondary=member_committee_table,
backref="members")
#query wrapper used in wtforms
def get_members():
#return m.Session.query(Member).all()
return m.Session.query(Member)
class CommitteeForm(BaseForm):
name = TextField('name', validators=[Required()])
members = QuerySelectMultipleField(query_factory=get_members())
这给我错误提示“查询”对象不可调用
解决方法:
摆脱'()’.
它需要一个方法工厂
members = QuerySelectMultipleField(query_factory=get_members)