Django / Python Query with variable number of arguments

Put all conditions in a kwargs dictionary:
kwargs = {}
kwargs[‘price__gt’] = 20
kwargs[‘category’] = ‘televisions’
kwargs[‘language’] = ‘NL/nl’

records = Product.objects.all().filter(**kwargs).select_related().order_by(‘order’)
Does the following:
Select all instances of de Product-model with a price higher then 20, in the category ‘televisions’ and language ‘NL/nl’.

Comments are closed.