diff options
Diffstat (limited to 'app/budget/models.py')
-rw-r--r-- | app/budget/models.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/app/budget/models.py b/app/budget/models.py index 7b7da75..6d1d113 100644 --- a/app/budget/models.py +++ b/app/budget/models.py @@ -41,13 +41,14 @@ class LuxPurchaseStatsManager(models.Manager): return self.filter(date_recorded__range=(start_date, end_date)).aggregate(Sum('amount')) def get_monthly_spending_by_category(self, cat, number_of_months=1): + cat = LuxSpendingCategory.objects.get(name=cat) today = timezone.now() month = today.replace(day=1).month start_month = month - number_of_months + 1 start_date = datetime.date(timezone.now().year, start_month, 1) last_day = calendar.monthrange(timezone.now().year, month)[1] end_date = datetime.date(timezone.now().year, month, last_day) - return self.filter(date_recorded__range=(start_date, end_date)).filter(category=cat).aggregate(Sum('amount')) + return self.filter(date_recorded__range=(start_date, end_date)).filter(cat=cat).aggregate(Sum('amount')) class LuxPurchase(models.Model): |