You can do something like this:
my_filter = {} my_filter[my_keyword] = my_filter_value my_object = MyModel.objects.filter(**my_filter)
As an example, your variables might be:
my_keyword = 'price__gte' my_filter_value = 10
This will get all the objects using price >= 10 . If you want to request more than one field, you can simply add another line below my_filter[my_keyword] :
my_filter[my_keyword] = my_filter_value my_filter[my_other_keyword] = my_other_filter_value
source share