Presumably you'll eventually have enough transactions that you'll want to start paging them. At that point, it would change how you would arrive at the balance. If a user is looking at page 30, you shouldn't need to retrieve the transactions from pages 1-29.
Eventually, you may want to consider something like this: from django.db.models import Sum PER_PAGE = 20 ... page = request.GET.get('page') or 1 start = (page - 1) * PER_PAGE end = start + PER_PAGE trans = Transaction.objects.order_by('date', 'id')[start:end] earliest = trans[0] qs = Transaction.objects.filter(date__lte=earliest.date, id__lt=earliest.id) previous = qs.aggregate(debit=Sum('debit'), credit=Sum('credit')) balance = previous['debit'] balance -= previous['credit'] transaction_list = [] for tran in trans: balance = balance + tran.debit balance = balance - tran.credit transaction_list.append({'transaction':tran,'balance':balance}) --Jeremy -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.