Answer the question
In order to leave comments, you need to log in
Is it possible to dynamically substitute the table name?
I have a dictionary like key : value. The key contains the name of the column, value contains its value. Is it possible somehow in the dynamics to substitute the values of the keys as identifiers of the names of the columns.
query = session.query(Transaction)
for k, v in incl.items():
if isinstance(v, list):
query = query.filter(Transaction.id.in_(v))
query = query.filter(Transaction.key1.in_(v))
query = query.filter(Transaction.key2.in_(v))
query = query.filter(Transaction.key3.in_(v))
Answer the question
In order to leave comments, you need to log in
query = session.query(Transaction)
for k, v in incl.items():
column = getattr(Transaction, k)
if isinstance(v, list):
query = query.filter(column.in_(v))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question