代码之家  ›  专栏  ›  技术社区  ›  Tri

Flask admin如何删除编辑和删除记录的操作

  •  0
  • Tri  · 技术社区  · 7 年前

    瓶子 和使用 烧瓶管理员 角色 在这个应用程序中 , 和 父母亲 谁想看到自己的孩子上学。

    角色 对于 和 学校行政 ,这是 超级用户 可以创建 学校行政 ,以及 可以添加、编辑或删除学生数据。

    学校行政 模型视图:

    class SchoolAdminModelView(sqla.ModelView):
        def is_accessible(self):
            if not current_user.is_active or not current_user.is_authenticated:
                return False
            if current_user.has_role('schooladmin'):
                return True
            return False
        def _handle_view(self, name, **kwargs):
            if not self.is_accessible():
                if current_user.is_authenticated:
                    abort(403)
                else:
                    return redirect(url_for('security.login', next=request.url))
    

    但是对于

    如下图所示: enter image description here 这就是问题所在 学校行政 视图,现在查看 父母亲

    那么,如何做到这一点。。?

    1 回复  |  直到 7 年前
        1
  •  2
  •   gittert    7 年前

    根据文件 https://flask-admin.readthedocs.io/en/latest/api/mod_model/#flask.ext.admin.model.BaseModelView.can_create 可以向模型添加属性,如编辑、删除、创建。只需在需要时将其绑定到特定角色即可。

    推荐文章