On 5/6/2009 10:27 AM, mamco wrote: > I have two models "Deposit" and "Cheque". I'm trying to show total > the amount of cheques in the admin area using the method name in the > list_display. It seems to work (although I think the documentation > suggests it may not because it requires the lookup for each row > shown). > > I've got this in the admin.py > class DepositAdmin(admin.ModelAdmin) > list_display = ('date', 'cash', 'ChequeTotal') > > and in the Deposit model: > > def chequeTotal(self): > return '%s' % Cheque.objects.aggregate(cheque_sum=Sum('amount')) > > The problem I'm having is that it is displayed as: > {'cheque_sum': Decimal('123.12')} > in the list. How do I get that to display just the 123.12? > > I know this is likely a simply python question, but not sure what that > returned format is called in order to search accordingly for an > answer.
The object being returned back by aggregate is a Python dictionary. In this case, you just want the value of the 'checkque_sum' element, so: {{{ return '%s' %Cheque.objects.aggregate(cheque_sum=Sum('amount'))['cheque_sum'] }}} -- George --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---