Flask-admin 如何去除编辑和删除记录的动作

Flask-admin how to remove the action for edit and delete record

我使用 Flask 制作了一个学费支付应用程序,并使用 Flask-admin 来管理付款。此应用程序中有三个角色,即超级用户学校管理员 parent 谁想看看他们的 children 学费。

我知道如何为超级用户学校管理员设置角色,即超级用户可以创建学校管理员学校管理员可以添加和编辑或删除一个学生数据。

到目前为止,这是我的 学校管理员 模型视图的代码:

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))

但对于 parent,我希望 parent 帐户只能查看或读取数据而无需修改数据。

喜欢下面这张图片: 那是school admin视图,现在对于parent帐户我要删除编辑和删除图标或功能是。

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

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