[Answer]-Efficiently doing thousands of lookups in a single table via django's ORM?

1👍

You are close. The use of Q() for creating complex OR queries is the key. Try something like this:

import operator
qs = []
for r in all_records:
    qs.append(Q(name=r.name, thing=r.thing, more=r.more))
Users.objects.filter(reduce(operator.or_, qs))

Leave a comment