1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
from django.db import models
from django.core.urlresolvers import reverse
from django.utils import timezone
CATS = (
('1', "Groceries"),
('2', "Restaurants"),
('3', "Camping"),
('4', "Petrol"),
('5', "Bus"),
('6', "Misc"),
)
class Trip(models.Model):
name = models.CharField(max_length=200)
slug = models.SlugField()
start = models.DateTimeField(default=timezone.now, blank=True, null=True)
end = models.DateTimeField(default=timezone.now, blank=True, null=True)
dek = models.TextField(null=True, blank=True)
def __str__(self):
return self.name
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)
amount = models.DecimalField(max_digits=8, decimal_places=2)
date = models.DateTimeField(default=timezone.now)
notes = models.TextField(null=True, blank=True)
category = models.CharField(max_length=2, choices=CATS, default=1)
trip = models.ForeignKey(Trip, null=True)
class Meta:
ordering = ('-date',)
def __str__(self):
return self.name
def date_month(self):
return self.date.strftime("%b %Y")
|