I am wondering if it is possible to do more advanced calculations in a query?
Here I am getting the data fine and want to add the profit which is the Sum(credit) - Sum(debit).
my error: Cannot compute Sum('credit'): 'credit' is an aggregate
trd = Trades.objects.all ().filter ( acct_id = acct.id )
.values ( 'issue' )
.annotate (
cnt = Count ( 'issue' ),
debit = Sum ( 'debit' ),
credit = Sum ( 'credit' ),
shrs = Sum ( 'shares' ),
profit = Sum ( 'credit' ) - Sum ( 'debit' )
)
.order_by ( 'issue' )
Thanks.