From 2da8980be4124fa06cd898905be2c4887834cbd5 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 29 May 2015 15:59:08 +0100 Subject: [PATCH] Fix for postgres requring an explicit definition of what the output field type is with summing mixed fields --- RIGS/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RIGS/models.py b/RIGS/models.py index 3b3024a7..ebd22970 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -297,7 +297,9 @@ class Event(models.Model, RevisionMixin): #total = 0.0 #for item in self.items.filter(cost__gt=0).extra(select="SUM(cost * quantity) AS sum"): # total += item.sum - total = EventItem.objects.filter(event=self).aggregate(sum_total=models.Sum(models.F('cost')*models.F('quantity')))['sum_total'] + total = EventItem.objects.filter(event=self).aggregate( + sum_total=models.Sum(models.F('cost')*models.F('quantity'), output_field=models.DecimalField(max_digits=10, decimal_places=2)) + )['sum_total'] if total: return total return Decimal("0.00")