diff --git a/nummi/main/models.py b/nummi/main/models.py index 38aa299..f635fbe 100644 --- a/nummi/main/models.py +++ b/nummi/main/models.py @@ -162,11 +162,17 @@ class Snapshot(models.Model): def sum(self): if self.previous is None: return None - trans = Transaction.objects.filter( - date__lt=self.date, date__gte=self.previous.date - ).aggregate(sum=models.Sum("value")) + trans = self.transactions.aggregate(sum=models.Sum("value")) return trans["sum"] or 0 + @property + def transactions(self): + if self.previous is None: + return Transaction.objects.none() + return Transaction.objects.filter( + date__lte=self.date, date__gt=self.previous.date + ) + class Meta: ordering = ["-date"] diff --git a/nummi/main/templates/main/snapshot.html b/nummi/main/templates/main/snapshot.html index a85bca7..6abb631 100644 --- a/nummi/main/templates/main/snapshot.html +++ b/nummi/main/templates/main/snapshot.html @@ -35,10 +35,10 @@ -{% if transactions %} +{% if snapshot.transactions %}