[Fixed]-Django 1.6 ORM count subset of related items

1👍

See the documentation on the order of annotate() and filter() clauses.

As that section says, if you filter before you annotate, then the annotation will only include elements matched by the filter. So:

BlogEntry.objects.filter(tags__in=tag_list).annotate(match=Count(tags))

Leave a comment