Having trouble figuring this one out.

class ParentObj:
id = UUIDField(primary_key=True)

class ChildObj:
id = UUIDField(primary_key=True)
parent = models.ForeignKey(ParentObj)
attr1 = models.CharField(max_length=128)
attr2 = models.IntegerField()

If you filter one table based on it's children tables parameters like so:

models.ParentObj.objects.filter(Q(childobj__attr1="something", 
childobj__attr2__gte=100)).count()

Let's say you get 1 and there are 10 total tables. Assuming that,

models.ParentTable.objects.filter(~Q(childtable__attr1="something", 
childtable__attr2__gte=100)).count()

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?

Thanks,
Matt

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/GrxGO9d8KVQJ.
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.

Reply via email to