"exclude" by annotation works like "filter"
"Exclude" by annotation does not negate lookup parameters:
>>> [g.num for g in Group.objects.annotate(num=Count('sites')).exclude(num=73)]
[73]
>>> [g.num for g in Group.objects.annotate(num=Count('sites')).filter(num=73)]
[73]
>>> e = Group.objects.annotate(num=Count('sites')).exclude(num=73).query.as_sql()
>>> f = Group.objects.annotate(num=Count('sites')).filter(num=73).query.as_sql()
>>> e == f
True
>>> Group.objects.annotate(num=Count('sites')).exclude(num=73).query.as_sql()
(u'SELECT (...), COUNT(`sites`.`id`) AS `num` FROM `site_groups` LEFT OUTER JOIN `sites` ON (`site_groups`.`id` = `sites`.`group_id`) GROUP BY site_groups.id HAVING COUNT(`urls`.`id`) = %s ORDER BY NULL', (73,))
Change History
(3)
Resolution: |
→ fixed
|
Status: |
new → closed
|
Component: |
ORM aggregation → Database layer (models, ORM)
|
sorry, there should be
sites
in HAVING as well, of course :)