This is mistake? I am not good at SQL, but it looks like the aggregate function does not take into account the highlighted () passed to the query set.
distinct_queryset = MyModel.objects.filter(reverse_relationship__icontains='foo').distinct()
iterated_total = 0
for item in distinct_queryset:
iterated_total += item.total
aggregate = queryset.aggregate(Sum('total'))
aggregate is Decimal('42201.20')
iterated_total is Decimal('38212.20')
aggregate is not total
source
share