I assume that by 'true'.capitalize() you mean the boolean value True , not the string 'True'
First convert 'True' to True . Then create a dictionary containing the keyword arguments that will be passed to queryset.filter . I take these two steps in one dictionary understanding:
vars = {'fridge': fridge, 'toilet': toilet, 'side_window': side_window} kwargs = {kw: True for kw in vars if vars[kw] == 'true'}
If you are not familiar with understanding, this is equivalent to:
kwargs = {} for kw in vars: if vars[kw] == 'true': kwargs[vars] = True
Then unzip this dictionary and pass it to queryset.filter :
queryset = queryset.filter(**kwargs)
Unpacking a dictionary is equivalent to passing it to key / value pairs as arguments to a function keyword.
f(a=1, b=2) # is equivalent to kw = {'a': 1, 'b': 2} f(**kw)
As a note, I don't know about queryset , but it looks like a module. If so, I would not suggest reassigning the result of queryset.filter to queryset ...
source share