我正在使用flask和Flask-Admin扩展名。我有两个模型(使用sql炼金术):
Project具有以下属性:
tasks = db.relationship('Task', backref=db.backref('project'))
任务是一个自引用树结构,其任务:
中的键列children = db.relationship("Task",
# cascade deletions
cascade="all, delete-orphan",
# many to one + adjacency list - remote_side
# is required to reference the 'remote'
# column in the join condition.
backref=db.backref("parent", remote_side=id),
# children will be represented as a dictionary
# on the "title" attribute.
collection_class=attribute_mapped_collection('title'),
)
我想要一个Flask-Admin的列表模板,向我展示所有项目。使用扩展和标准列表视图可以轻松完成此操作。但是现在我想为点击项目时应该出现的任务添加CRUD接口(例如:http://examples.flask-admin.org/sqla/simple/admin/userview/)。
我不知道实现这一目标的最佳途径是什么。我想在项目行的每个表格单元格中为任务包含一个iframe。但这有点难看。如何在项目列表模板中为属于其项目的任务呈现CRUD接口?
我知道Flask-Admin能够将两个表链接在一起(通过模型中的外键),但标准方式不是我想要的,因为它需要至少一次点击才能从项目中获取任务crud接口的接口。我想要的是将两个crud接口加载到同一页面上。
答案 0 :(得分:1)
查看文档看起来就像为Project
模型视图提供inline-models
类属性一样简单:
class ProjectModelView(ModelView):
inline_models = (Task, )