1

I'm using Flask-Admin to manage my dashboard, there are few roles in my app, two of them are superuser and client.

Now, I have User table build by Flask-SQLAlchemy, and now I want to manage the table by users role. Which means the superuser can edit user roles in the Flask-Admin form, and in the other client can't do it or the form are not displayed.

Like this screenshot: enter image description here there are edit form by superuser role. But for now, I want the edit form not displayed if the current user has role client.

So, in logically I want to making something like this:

class UserModelView(sqla.ModelView):
    if current_user.has_role('superuser'):
        form_excluded_columns = ('created_at', 'updated_at')
    else:
        form_excluded_columns = ('created_at', 'updated_at', 'roles')
Tri
  • 2,722
  • 5
  • 36
  • 65
  • 1
    It is a common problem in using Flask-Admin. Look at this [answer](https://stackoverflow.com/a/47469875/6682517), it is very close to what you are trying to achieve. – Sergey Shubin Apr 03 '19 at 12:30
  • 1
    Thanks very much @SergeyShubin, it works perfectly :) – Tri Apr 03 '19 at 14:11

1 Answers1

1

I following @SergeyShubin advice to following his answer here and in that case are very similar with my case and it works perfectly.

Also @SergeyShubin answer here also similar with my case. Thanks very much @SergeyShubin.

Tri
  • 2,722
  • 5
  • 36
  • 65