flask sqlalchemy query with keyword as variable
Let's say I have a model like this: class User(db.Model): id = db.Column(db.Integer, primary_key=True) hometown = db.Column(db.String(140)) university = db.Column(db.String(140)) To get a list of users from New York, this is my query: User.query.filter_by(hometown='New York').all() To get a list of users who go to USC, this is my query: User.query.filter_by(university='USC').all() And to get a list of users from New York, and who go to USC, this is my query: User.query.filter_by(hometown='New York').filter_by(university='USC').all() Now, I would like to dynamically generate these queries based