OK, so I have the following model:
Transaction
currency_code: CharField
date_time: DateTimeField
price: IntegerField
I'd like to make a query which returns a dictionary of distinct days, with totals for all transactions under each currency_code. So something like:
{
'2012/05/01': {
'USD': 5000,
'EUR': 3500,
}
'2012/05/02': {
'USD' ...
So far I've got this query, but I'm kind of stuck:
Transaction.objects.extra({'date' : 'date(date_time)'}).values('date', 'currency_code').annotate(Sum('price'))
This gets me a result which looks like the following:
[
{'date': datetime.date(2012, 5, 1), 'price__sum': 5000, 'currency_code': 'USD'}
{'date': datetime.date(2012, 5, 1), 'price__sum': 3500, 'currency_code': 'EUR'}
...
]
Any advice on how I can get my query to group by date? Thanks in advance!