简体   繁体   中英

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

I make a tuition payment app using Flask and using Flask-admin to managing the payment. There is three role in this app which is superuser , school admin and the parent who want to see their children tuition.

I know how to make the role for the superuser and the school admin , which is the superuser can create the school admin , and the school admin can add and edit or delete a student data.

so far, this my code for the school admin modelview:

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

But for the parent , I want the parent account just can see or read data without access to modify it.

Like this image below: 在此处输入图片说明 That is the school admin view, now for the parent account I want to remove the edit and delete icon or the feature is.

So, how to do that..?

According to the docs https://flask-admin.readthedocs.io/en/latest/api/mod_model/#flask.ext.admin.model.BaseModelView.can_create You can add attributes to a model like edit, delete, create. Just bind this to a specific role where needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM