Home

mint @e9a605f47f57723424ae99e169737262e9b0d31d - refs - log -
-
https://git.jolheiser.com/mint.git
Budget
mint / budget / models.py
- raw -
 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
from django.db import models
from django.db.models import Manager


class Recurrence(models.TextChoices):
    MONTH = "M", "Monthly"
    WEEK = "W", "Weekly"

    @staticmethod
    def comment() -> str:
        return " | ".join([f"{v[0]} ({v[1]})" for v in Recurrence.choices])

class Transaction(models.Model):
    title = models.CharField(max_length=100)
    cents = models.BigIntegerField()
    date = models.DateField()
    recurrence = models.CharField(max_length=1, choices=Recurrence.choices, db_comment=Recurrence.comment())
    week = models.IntegerField()
    is_income = models.BooleanField(default=False)

    @property
    def amount(self) -> float:
        return self.cents / 100

    @property
    def display(self) -> str:
        return f"{self.title} (${self.amount:,.2f})"

    def __str__(self):
        return self.display