[Answered ]-Django aggregate and Distinct together

1👍

You can first annotate with the Min sellingPrice (or another tie breaker) for each uniqueKey, and then aggregate, so:

from django.db.models import Min, Sum

rooms.objects.values('uniquekey').annotate(
    min=Min('sellingPrice')
).aggregate(
    sellingPrice__sum=Sum('min')
)

Leave a comment