Replies: 1 comment
-
The best way would be to add both views to the admin interface and block access depending on the user. You can block access |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Dear Author,
In the official documentation, it is mentioned that we can create a "single admin" or "multiple admins." I have a question related to "single admin" and dynamically configuring ModelView instances based on the role of the authenticated user.
Let's assume I have defined the Post model and the following ModelView classes:
AdminPostView(ModelView) – for users with the role admin.
StaffPostView(ModelView) – for users with the role staff.
I have implemented a custom AuthProvider, UserAuthProvider, where I have defined the methods login(), logout(), and is_authenticated(). Then, I initialized the Admin object as follows:
As per the documentation, I should add all ModelView instances using the add_view() method:
user.add_view(...)
My question is: How can I dynamically add a specific ModelView based on the role of the authenticated user? For example:
If the user has the role admin, I want to add:
user.add_view(AdminPostView(model=Post))
If the user has the role staff, I want to add:
user.add_view(StaffPostView(model=Post))
Is it possible to implement this logic directly within a "single admin"? If so, what would be the recommended approach to achieve this?
Thank you in advance for your assistance!
Beta Was this translation helpful? Give feedback.
All reactions