How to give column name dynamically from string variable in sql alchemy filter?

Just use getattr standard python library function to get an attribute by name:

col_name="subject"
db_session.query(Notice).filter(getattr(Notice, col_name).like("%" + query + "%"))

Leave a Comment