As you pointed out ( # 15546 ), there might be a bug in django.
But as a workaround, you can put the load on the actual calculation in python instead of the SQL database by doing something like this:
[{'field_c': model['field_c'], 'percent': m['sum_field_a'] * 100.0 / m['sum_field_b']} for model in MyModel.objects.values('field_c').annotate( sum_field_a=Sum('field_a'), sum_field_b=Sum('field_b')).order_by('field_c')]
Since this solution forces you to iterate over all the data, depending on what you want to do, it may or may not be acceptable.
Xixi
source share