views:

121

answers:

1

How can I filter in a query so the result excludes any object instances with ID belonging to a list?

Lets say I have:

object_id_list = [1, 5, 345]

MyObject.objects.filter(Q(time__gte=datetime.now()) & Q( ... what to put here? ... ))

Something in the style of "SELECT * FROM ... WHERE id NOT IN (...)"

+2  A: 
MyObject.objects.filter(time__gte=datetime.now()).exclude(id__in=object_id_list)
Ignacio Vazquez-Abrams