summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/expenses/admin.py16
-rw-r--r--app/expenses/migrations/0001_initial.py48
-rw-r--r--app/expenses/migrations/0002_luxexpense.py26
-rw-r--r--app/expenses/migrations/0003_auto_20170429_0748.py40
-rw-r--r--app/expenses/migrations/__init__.py0
-rw-r--r--app/expenses/models.py31
-rw-r--r--app/expenses/urls.py7
-rw-r--r--app/expenses/views.py13
8 files changed, 168 insertions, 13 deletions
diff --git a/app/expenses/admin.py b/app/expenses/admin.py
index 28c8869..a754883 100644
--- a/app/expenses/admin.py
+++ b/app/expenses/admin.py
@@ -1,15 +1,25 @@
from django.contrib import admin
-from .models import Expense, Trip
+from .models import LuxExpense, Trip, Expense, Month
+@admin.register(Trip)
class TripAdmin(admin.ModelAdmin):
list_display = ('name', 'start')
+@admin.register(Expense)
class ExpenseAdmin(admin.ModelAdmin):
list_display = ('name', 'category', 'amount', 'date_month')
list_filter = ('date', 'category')
-admin.site.register(Expense, ExpenseAdmin)
-admin.site.register(Trip, TripAdmin)
+
+@admin.register(LuxExpense)
+class LuxExpenseAdmin(admin.ModelAdmin):
+ list_display = ('category', 'amount', 'month')
+ list_filter = ('month', 'category')
+
+
+@admin.register(Month)
+class MonthAdmin(admin.ModelAdmin):
+ pass
diff --git a/app/expenses/migrations/0001_initial.py b/app/expenses/migrations/0001_initial.py
new file mode 100644
index 0000000..5ff70cd
--- /dev/null
+++ b/app/expenses/migrations/0001_initial.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9 on 2017-04-28 22:47
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import django.utils.timezone
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Expense',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=200)),
+ ('amount', models.DecimalField(decimal_places=2, max_digits=8)),
+ ('date', models.DateTimeField(default=django.utils.timezone.now)),
+ ('notes', models.TextField(blank=True, null=True)),
+ ('category', models.CharField(choices=[('1', 'Groceries'), ('2', 'Restaurants'), ('3', 'Camping'), ('4', 'Petrol'), ('5', 'Bus'), ('6', 'Misc')], default=1, max_length=2)),
+ ],
+ options={
+ 'ordering': ('-date',),
+ },
+ ),
+ migrations.CreateModel(
+ name='Trip',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=200)),
+ ('slug', models.SlugField()),
+ ('start', models.DateTimeField(blank=True, default=django.utils.timezone.now, null=True)),
+ ('end', models.DateTimeField(blank=True, default=django.utils.timezone.now, null=True)),
+ ('dek', models.TextField(blank=True, null=True)),
+ ],
+ ),
+ migrations.AddField(
+ model_name='expense',
+ name='trip',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='expenses.Trip'),
+ ),
+ ]
diff --git a/app/expenses/migrations/0002_luxexpense.py b/app/expenses/migrations/0002_luxexpense.py
new file mode 100644
index 0000000..9edfdb4
--- /dev/null
+++ b/app/expenses/migrations/0002_luxexpense.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9 on 2017-04-28 22:48
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.utils.timezone
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('expenses', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='LuxExpense',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('category', models.CharField(choices=[('1', 'Groceries'), ('2', 'Restaurants'), ('3', 'Camping'), ('4', 'Petrol'), ('5', 'Bus'), ('6', 'Misc')], default=1, max_length=2)),
+ ('amount', models.DecimalField(decimal_places=2, max_digits=8)),
+ ('date', models.DateTimeField(default=django.utils.timezone.now)),
+ ('notes', models.TextField(blank=True, null=True)),
+ ],
+ ),
+ ]
diff --git a/app/expenses/migrations/0003_auto_20170429_0748.py b/app/expenses/migrations/0003_auto_20170429_0748.py
new file mode 100644
index 0000000..69f14ec
--- /dev/null
+++ b/app/expenses/migrations/0003_auto_20170429_0748.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9 on 2017-04-29 07:48
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import django.utils.timezone
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('expenses', '0002_luxexpense'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Month',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=200)),
+ ('year', models.IntegerField()),
+ ('date', models.DateTimeField(default=django.utils.timezone.now)),
+ ('notes', models.TextField(blank=True, null=True)),
+ ],
+ ),
+ migrations.RemoveField(
+ model_name='luxexpense',
+ name='date',
+ ),
+ migrations.RemoveField(
+ model_name='luxexpense',
+ name='notes',
+ ),
+ migrations.AddField(
+ model_name='luxexpense',
+ name='month',
+ field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='expenses.Month'),
+ ),
+ ]
diff --git a/app/expenses/migrations/__init__.py b/app/expenses/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/app/expenses/migrations/__init__.py
diff --git a/app/expenses/models.py b/app/expenses/models.py
index bca23bf..ff33844 100644
--- a/app/expenses/models.py
+++ b/app/expenses/models.py
@@ -3,13 +3,12 @@ from django.core.urlresolvers import reverse
from django.utils import timezone
CATS = (
- ('1', "Travco"),
- ('2', "Groceries"),
- ('3', "Lodging"),
- ('4', "Camping"),
- ('5', "Restaurants"),
- ('6', "Petrol"),
- ('7', "Misc"),
+ ('1', "Groceries"),
+ ('2', "Restaurants"),
+ ('3', "Camping"),
+ ('4', "Petrol"),
+ ('5', "Bus"),
+ ('6', "Misc"),
)
@@ -26,6 +25,24 @@ class Trip(models.Model):
def get_absolute_url(self):
return reverse("expenses:list_expense", kwargs={"slug": self.slug})
+class Month(models.Model):
+ name = models.CharField(max_length=200)
+ year = models.IntegerField()
+ date = models.DateTimeField(default=timezone.now)
+ notes = models.TextField(null=True, blank=True)
+
+ def __str__(self):
+ return "%s %s" %(self.name, self.year)
+
+class LuxExpense(models.Model):
+ category = models.CharField(max_length=2, choices=CATS, default=1)
+ amount = models.DecimalField(max_digits=8, decimal_places=2)
+ month = models.ForeignKey(Month, null=True)
+
+ def __str__(self):
+ return '%s-%s' %(self.month, self.get_category_display())
+
+
class Expense(models.Model):
name = models.CharField(max_length=200)
diff --git a/app/expenses/urls.py b/app/expenses/urls.py
index 6b146c3..6ad732e 100644
--- a/app/expenses/urls.py
+++ b/app/expenses/urls.py
@@ -4,9 +4,14 @@ from . import views
app_name = "expenses"
urlpatterns = [
+ #url(
+ # r'(?P<slug>[-\w]+)$',
+ # views.ExpenseListView.as_view(),
+ # name='list_expense'
+ #),
url(
r'(?P<slug>[-\w]+)$',
- views.ExpenseListView.as_view(),
+ views.LuxExpenseListView.as_view(),
name='list_expense'
),
url(
diff --git a/app/expenses/views.py b/app/expenses/views.py
index 3a8d2cb..98a4c70 100644
--- a/app/expenses/views.py
+++ b/app/expenses/views.py
@@ -1,7 +1,6 @@
from django.views.generic import ListView
-from .models import Expense, Trip, CATS
-
+from .models import LuxExpense, Expense, Trip, CATS
class ExpenseListView(ListView):
model = Expense
@@ -19,6 +18,16 @@ class ExpenseListView(ListView):
context['categories'] = CATS
return context
+class LuxExpenseListView(ListView):
+ model = LuxExpense
+ context_object_name = 'object_list'
+ template_name = 'details/expenses.html'
+
+ def get_context_data(self, **kwargs):
+ # Call the base implementation first to get a context
+ context = super(LuxExpenseListView, self).get_context_data(**kwargs)
+ context['categories'] = CATS
+ return context
class TripListView(ListView):
model = Trip