سؤال

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

هل كانت مفيدة؟

المحلول

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top