Let's write this in logical notation models.ParentObj.objects.filter(Q(childobj__attr1="something", > childobj__attr2__gte=100)).count()
A AND B This query should give you all objects where both attr1="something" is true AND attr2_gte=100 is true. Does this sound right from the data you have at hand? > models.ParentTable.objects.filter(~Q(childtable__attr1="something", > childtable__attr2__gte=100)).count() > ~ ( A AND B ) = ~A OR ~B This query should (at least according to logic, I'm not sure according to Django's ORM) give you all objects where EITHER attr1="something" is false OR attr2 >= 100 is false. Again, does your data set show this is true? > > Should return 9, however, it instead returns all ParentObjects that have > AT LEAST ONE child where attr1 is not "something" and ALL children have > attr2 less than 100. It seems that the ~Q() does two seperate lookups on > childtable for attr1 and attr2 instead of comparing both with one lookup. > > Am I missing something? > I believe ... just from reading what you've posted, that you actually want the Complement of the set of objects. Maybe something along these lines would help you? http://stackoverflow.com/questions/8820113/django-getting-complement-of-queryset Anyways, Good luck! -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.