Django annotate count with a distinct field

Count can take a distinct argument, like so:

p = Project.objects.all().annotate(Count('informationunit__username', 
                                         distinct=True))

This doesn’t seem to be documented, but you can find it in the source for Count.

Leave a Comment