diff options
Diffstat (limited to 'app/budget/views.py')
-rw-r--r-- | app/budget/views.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/app/budget/views.py b/app/budget/views.py index 3743eaf..e291bde 100644 --- a/app/budget/views.py +++ b/app/budget/views.py @@ -1,5 +1,7 @@ +import datetime from django.shortcuts import render from django.views.generic.edit import CreateView, UpdateView +from django.utils import timezone from utils.views import PaginatedListView from .models import LuxPurchase @@ -9,5 +11,35 @@ class PurchaseModelFormView(CreateView): success_url = '/spending/' template_name = 'budget/create_form.html' + +class PurchaseUpdateView(UpdateView): + model = LuxPurchase + fields = ['amount', 'source', 'category'] + success_url = '/spending/' + template_name = 'budget/update_form.html' + + class LuxPurchaseListView(PaginatedListView): - pass + model = LuxPurchase + + def get_context_data(self, **kwargs): + ''' + Get Monthly Spending for a nice bar chart + ''' + # Call the base implementation first to get a context + context = super(LuxPurchaseListView, self).get_context_data(**kwargs) + context['monthly_spending'] = LuxPurchase.stats.get_monthly_spending() + today = timezone.now() + first = today.replace(day=1) + month_1 = first - datetime.timedelta(days=1) + month_2 = month_1.replace(day=1) - datetime.timedelta(days=1) + month_3 = month_2.replace(day=1) - datetime.timedelta(days=1) + context['month'] = today.strftime('%h') + context['monthly_spending_1'] = LuxPurchase.stats.get_monthly_spending(month_1.month) + context['month_1'] = month_1.strftime('%h') + context['monthly_spending_2'] = LuxPurchase.stats.get_monthly_spending(month_2.month) + 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) + return context |