From b49342cd534a3384d86b49e3c77f632e0d01edc9 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Sat, 12 Nov 2022 11:50:20 -0600 Subject: bdgt: added category level monthly stats --- app/budget/models.py | 20 ++++++++++++++++++++ app/budget/templates/budget/luxpurchase_list.html | 12 ++++++++++++ app/budget/views.py | 3 ++- 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'app/budget') diff --git a/app/budget/models.py b/app/budget/models.py index f4c6ec0..7afc4e2 100644 --- a/app/budget/models.py +++ b/app/budget/models.py @@ -14,6 +14,26 @@ class LuxSource(models.Model): return self.name +class LuxFixedMonthly(models.Model): + name = models.CharField(max_length=200) + source = models.ForeignKey(LuxSource, on_delete=models.CASCADE) + CATEGORY = ( + (0, 'Grocery & Home'), + (1, 'Gas'), + (2, 'Bus'), + (3, 'Lodging'), + (4, 'Books'), + (5, 'Clothes'), + (6, 'Eating Out'), + (7, 'Misc'), + ) + category = models.IntegerField(choices=CATEGORY, default=0) + date_recorded = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return self.name + + class LuxPurchaseStatsManager(models.Manager): def get_monthly_spending(self, month=timezone.now().month): diff --git a/app/budget/templates/budget/luxpurchase_list.html b/app/budget/templates/budget/luxpurchase_list.html index 765834a..20e0d4e 100644 --- a/app/budget/templates/budget/luxpurchase_list.html +++ b/app/budget/templates/budget/luxpurchase_list.html @@ -30,6 +30,18 @@ {{month}} Total: ${{monthly_spending.amount__sum}} + + + + {{month}} Food Total: + ${{food_total.amount__sum}} + + + + + {{month}} Lodging Total: + ${{lodge_total.amount__sum}} +

Previous Monthly Spending

diff --git a/app/budget/views.py b/app/budget/views.py index 4a2ab74..c168ae1 100644 --- a/app/budget/views.py +++ b/app/budget/views.py @@ -52,5 +52,6 @@ class LuxPurchaseListView(PaginatedListView): context['month_2'] = month_2.strftime('%h') context['monthly_spending_3'] = LuxPurchase.stats.get_monthly_spending(month_3.month) context['month_3'] = month_3.strftime('%h') - context['cat'] = LuxPurchase.stats.get_monthly_spending_by_category(1, 3) + context['food_total'] = LuxPurchase.stats.get_monthly_spending_by_category(0, 1) + context['lodge_total'] = LuxPurchase.stats.get_monthly_spending_by_category(3, 1) return context -- cgit v1.2.3-70-g09d2