Question

I'm using flask-admin to create a simple backend for my database. I'd like to only show parts of a table, based on a pre-filtering, based on the permissions the user has. For example, if the table has all the sales of a company, i would like to only show the sales of salesperson 'foo' when 'foo' accesses the backend

Était-ce utile?

La solution

I found the solution is overriding the method 'get_query'

It should return a SQLAlchemy query object.

def get_query(self):
    role = current_user.role
    if role == 'contributor':
        return # filtered query
    elif role == 'admin':
        return # unfiltered query
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top