Issue
I want to multiply two values in a queryset
how do I achieve this:
This is what I have :
def get_adjustment(self):
Adjustment.objects.filter(employee_month_id=1,adjustment_type=2)
.values('exchange_rate','amount').aggregate(Sum('amount', field="exchange_rate*amount")
Solution
You need to use F()
objects.
.values('exchange_rate','amount').aggregate(Sum(F('amount') * F('exchange_rate')))
See the query expressions docs.
Answered By - Daniel Roseman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.