Wednesday, September 17, 2014

Django Annotation: Users with duplicate emails

User.objects.values("email").annotate(num_emails=Count("email")
                    ).order_by("-num_emails").filter(
                    num_emails__count__gt=1):

Reference:
http://stackoverflow.com/questions/8989221/django-select-only-rows-with-duplicate-field-values

No comments: