Dados os modelos:
class Supporter(models.Model):
...
class Campaign(models.Model):
....
supporters = models.ManyToManyField(Supporter)
supporters_needed = models.PositiveIntegerField()
Se quisermos obter um conjunto de consultas das campanhas que atingiram o número de apoiadores necessários:
def campaigns_completed():
from django.db.models import Count
from django.db.models import F
return Campaign.objects.annotate(num_supporters=Count('supporters')).filter(num_supporters__gte=F('supporters_needed'))