Reputation: 101
Can someone provide a working example as described in the docs here;
class Person(Base):
__tablename__ = 'person'
id = Column(Integer, primary_key=True)
@classmethod
def query(cls):
return get_query_for_current_user(cls)
What should be returned by 'get_query_for_current_user()'
?
Upvotes: 0
Views: 657
Reputation: 527
You should return the query itself..
original_query = db.session.query(cls)
This will return the original query. After that you can basically add any filters to it and return the modified query.
For example.
if user.is_auth:
condition = (cls.id == 1)
else:
condition = (cls.id == 2)
return original_query.filter(condition)
Upvotes: 1