[Answered ]-Is it possible to use aggregate on a queryset annotation?

1👍

You can sum up, so:

from django.db.models import Count, Sum


MyModel.objects.annotate(total_m2m=Count('my_m2m')).aggregate(
    total=Sum('total_m2m')
)

but here it makes more sense to aggregate immediately:

from django.db.models import Count


MyModel.objects.aggregate(
    total=Count('my_m2m')
)

Leave a comment