summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/expenses/__init__.py0
-rw-r--r--app/expenses/admin.py10
-rw-r--r--app/expenses/models.py31
-rw-r--r--app/expenses/urls.py7
-rw-r--r--app/expenses/views.py12
-rw-r--r--app/lib/templatetags/templatetags/expense_total.py25
6 files changed, 85 insertions, 0 deletions
diff --git a/app/expenses/__init__.py b/app/expenses/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/expenses/__init__.py
diff --git a/app/expenses/admin.py b/app/expenses/admin.py
new file mode 100644
index 0000000..f014dca
--- /dev/null
+++ b/app/expenses/admin.py
@@ -0,0 +1,10 @@
+from django.contrib import admin
+
+from .models import Expense
+
+
+class ExpenseAdmin(admin.ModelAdmin):
+ list_display = ('name', 'category', 'amount', 'date_month')
+
+
+admin.site.register(Expense, ExpenseAdmin)
diff --git a/app/expenses/models.py b/app/expenses/models.py
new file mode 100644
index 0000000..a01b8d7
--- /dev/null
+++ b/app/expenses/models.py
@@ -0,0 +1,31 @@
+from django.db import models
+from django.template.defaultfilters import slugify
+import datetime
+
+CATS = (
+ ('1', "Yellowstone"),
+ ('2', "Suburban"),
+ ('3', "Groceries"),
+ ('4', "Lodging"),
+ ('5', "Camping"),
+ ('6', "Restaurants"),
+ ('7', "Petrol"),
+ ('8', "Misc"),
+)
+
+class Expense(models.Model):
+ name = models.CharField(max_length=200)
+ amount = models.DecimalField(max_digits=8, decimal_places=2)
+ date = models.DateTimeField(default=datetime.date.today())
+ notes = models.TextField(null=True, blank=True)
+ category = models.CharField(max_length=2, choices=CATS, default=1)
+
+ class Meta:
+ ordering = ('-date',)
+
+ def __str__(self):
+ return self.name
+
+ def date_month(self):
+ return self.date.strftime("%b %Y")
+
diff --git a/app/expenses/urls.py b/app/expenses/urls.py
new file mode 100644
index 0000000..ae7cad6
--- /dev/null
+++ b/app/expenses/urls.py
@@ -0,0 +1,7 @@
+from django.conf.urls import *
+from django.views.generic.base import RedirectView
+
+
+urlpatterns = patterns('',
+ url(r'yellowstone-suburban-trip-costs/', 'expenses.views.detail'),
+)
diff --git a/app/expenses/views.py b/app/expenses/views.py
new file mode 100644
index 0000000..7442178
--- /dev/null
+++ b/app/expenses/views.py
@@ -0,0 +1,12 @@
+from django.shortcuts import render_to_response, get_object_or_404
+from django.template import RequestContext
+
+from .models import Expense, CATS
+
+def detail(request):
+ context = {
+ 'object_list': Expense.objects.all(),
+ 'categories': CATS
+ }
+ return render_to_response('details/expenses.html', context, context_instance=RequestContext(request))
+
diff --git a/app/lib/templatetags/templatetags/expense_total.py b/app/lib/templatetags/templatetags/expense_total.py
new file mode 100644
index 0000000..8bf0953
--- /dev/null
+++ b/app/lib/templatetags/templatetags/expense_total.py
@@ -0,0 +1,25 @@
+from decimal import Decimal
+from django import template
+from django.utils.safestring import mark_safe
+register = template.Library()
+
+@register.filter
+def expense_total(values):
+ """
+ converts spaces to hyphens.
+ """
+ total = 0
+ for items in values:
+ for item in items['list']:
+ total += Decimal(item.amount)
+ return mark_safe(total)
+
+@register.filter
+def cat_total(values):
+ """
+ converts spaces to hyphens.
+ """
+ total = 0
+ for val in values:
+ total += Decimal(val.amount)
+ return mark_safe(total)