Im new to Django.
I have different classes (Stock, Portfolio, Trades)
What Im trying to achieve is a summery of all trades per stock.
So Basicly this is how my rows are now
I want to combine or group by stock_id
and do a sum of open_price
and quantity
.
I tried with
Trade.objects.filter(portfolio=1).values('stock__name').aggregate(stock_total=Count('stock',distinct=True))
But that doesnt work.
How do I need to write the query to get that result?
Try this:
from django.db.models import Count
Trade.objects.filter(portfolio=1).values('stock__name').annotate(stock_total=Count('entry'))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments