Subtract the aggregation of two sums in a view in Django -


im trying create profit field, im taking 2 aggregations of sums , subtracting them. unfortunately, can't seem way. there way of accomplishing this? i'd use model, im not calling in template

def view(request):     result_list = result.objects.order_by('-entryid')[:5]     django.db.models import sum     winnings = result.objects.all().aggregate(sum('winnings'), sum('entry'))     >>>>>>>>> profit = winnings.winnings__sum - winnings.entry__sum <<<<<<<<<<<      template = loader.get_template('result.html')     context = requestcontext(request, {         'result_list': result_list,         'winnings': winnings,         'profit': profit,     })     return httpresponse(template.render(context)) 

aggregate returns dictionary:

profit = winnings["winnings__sum"] - winnings["entry__sum"] 

that's why winnings.winnings__sum works in template not in python.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -