我有一个这样的 SQLAlchemy 模型:
class Group(Base):
__tablename__ = 'groups'
id = Column(Integer, primary_key = True, ca_include = True)
name = Column(String, ca_include = True)
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key = True, ca_include = True)
name = Column(String, ca_include = True)
group_id = Column(Integer, ForeignKey('groups.id'), nullable = True, ca_include = True)
group = relationship('Group', ca_include = True)
我使用的表单库是deform。我安装了ColanderAlchemy以自动将模型定义转换为 Colander Schema:
form = deform.Form(SQLAlchemyMapping(Group), use_ajax = True)
我可以做 form.render() 来得到一个空的表格。但是如何用记录填写这个空表格呢?我试过:
group = Group.get(1)
form.render(group)
但是失败了。我也关注了这个博客,但它只能将单个记录转换为滤锅的格式,但不会转换任何关系。那么...无论如何我可以将 SQLAlchemy 记录转换为滤锅记录吗?