diff options
Diffstat (limited to 'app/unused_apps/expenses/models.py')
-rw-r--r-- | app/unused_apps/expenses/models.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/app/unused_apps/expenses/models.py b/app/unused_apps/expenses/models.py new file mode 100644 index 0000000..fbcdd7a --- /dev/null +++ b/app/unused_apps/expenses/models.py @@ -0,0 +1,62 @@ +from django.db import models +from django.urls 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, on_delete=models.CASCADE, 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, on_delete=models.CASCADE, null=True) + + class Meta: + ordering = ('-date',) + + def __str__(self): + return self.name + + def date_month(self): + return self.date.strftime("%b %Y") |