I'm trying to build a query in python, I'm looking for an elegant way to append a WHERE condition in the middle of a string:
def get_raw_queryset(frequency=None, where_condition=None):
qs = "SELECT id, COUNT(*) AS count FROM user_transaction_log " \
# I WANT TO APPEND A WHERE ONLY IF not None
if where_condition:
"WHERE .... = 1" \
"GROUP BY type , strftime('{0}', datetime) ORDER BY id" \
.format(frequency)
return qs