Let say I have the following query:
query_result = Mymodel.objects.values('price').filter(price__gte=0)
If I want to generalize the query and put it in a function I could replace 'price'
with a variable:
def price_query(column_name):
query_result = Mymodel.objects.values(column_name).filter(column_name__gte=0)
return query_result
price_query('price')
The first replacement of 'price'
with column_name
works fine but how do I use the comparison __gte
with a variable instead of the field name.
Any help is much appreciated.