Django Filtering by FK more than x value count

django

Solution

from django.db.models import Count

Group.objects.annotate(c=Count('contacts')).filter(c__gt=1)

Documentation on Annotation and Aggregation. See also Filtering on Annotation.

Problem

I hope you can see what I'm trying to do with the following line... ``` Group.objects.filter(contacts.count>1) ``` I want to filter and only get groups that have more than 1 related contact. Above will not work so how should it be done? Thanks models.py ``` class Contact(models.Model): first_name = models.CharField(max_length=60) group = models.ForeignKey(Group, related_name='contacts') class Group(models.Model): name = models.CharField(max_length=60) ```

Original source