From a6f5c3773a08eafc1998cfb9a92cc8960a8cb190 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sun, 3 Jun 2012 15:23:41 +0200 Subject: [PATCH] Make it possible to find the sum of an invoice --- invoice/models.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/invoice/models.py b/invoice/models.py index 64f0710..ef2b8cd 100644 --- a/invoice/models.py +++ b/invoice/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models import Sum from invoice import settings from django.utils.translation import ugettext as _ @@ -23,6 +24,11 @@ class Invoice(models.Model): date = models.DateField() currency = models.CharField(max_length = 10) + def _total_sum(self): + return self.invoiceline_set.aggregate(total=Sum("amount"))["total"] + + total_sum = property(_total_sum) + class VAT(models.Model): """ Model representing different taxes to be used in Invoices""" name = models.CharField(_('name'), max_length=255) -- 2.39.5