Search code examples
pythondjangodjango-viewsdjango-ormdjango-shell

Access django dict through shell after aggregate annotate


Simple question I am trying to get the result of an aggregate to use in my view to make a simple calculation.

I have written the following.

sms_raised = SmsBacker.objects.values('amount').annotate(Sum('amount'))
sms_raised
[{'amount': 150L, 'amount__sum': 600}]

How do I access those values in the shell.

I have tried

sms_raised_amount
sms_raised__amount
sms_raised.amount

All with no luck


Solution

  • Dict is the first item in the list, so

    sms_raised[0]['amount']
    sms_raised[0]['amount__sum']