Last Updated: February 25, 2016
· fmariluis

Pass a QueryDict to a Django QuerySet

Let's suppose you have a captured QueryDict (for example, something you took from an admin url after applying a filter).

For example:
q = QueryDict('name=John&lastname=Smith')

Obviously in a real case the QueryDict would be the result of request.GET.

We can do this:

Thanks to the magic of dictionary unpacking, the last line will have the same result as:
People.objects.filter(name='John', lastname='Smith')

The dict() method was added en Django 1.4.