see what I have:
> bar = [(u'code__regex', u'^[^J]'), (u'active__exact', u'0'), (u'type__id__exact', u'E01')]
There are the fields/values that I want to use to filter the model Foo.
> #want to have this equivalent:
> Foo.objects.filter(bar)
Thanks!
This isn’t a django issue, this is a python issue. You want to pass the keyword pairs as keyword arguments (kwargs) to the filter. Your
baris perfect as a kwarg set, so thedict(bar)converts it to the dictionary, and the**prefix informs the python parser that the dictionary is to be interpreted as keyword arguments by the receiver.Stack overflow entry Understanding kwargs in Python covers this in more detail.