Add categories
This commit is contained in:
parent
3f73232312
commit
36be624f5c
3 changed files with 49 additions and 2 deletions
|
@ -3,15 +3,33 @@ from django.db import models
|
|||
from django.forms import ModelForm
|
||||
|
||||
|
||||
class Category(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(max_length=256)
|
||||
parent = models.ForeignKey("self", on_delete=models.SET_NULL, blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
if self.parent:
|
||||
return f"{self.parent}>{self.name}"
|
||||
else:
|
||||
return f"{self.name}"
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(max_length=256)
|
||||
description = models.TextField()
|
||||
value = models.DecimalField(max_digits=12, decimal_places=2)
|
||||
date = models.DateField()
|
||||
category = models.ForeignKey(
|
||||
Category, on_delete=models.SET_NULL, blank=True, null=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.date} {self.name}: {self.value}€"
|
||||
res = f"{self.date} {self.name}: {self.value}€"
|
||||
if self.category:
|
||||
return f"{res} ({self.category})"
|
||||
return res
|
||||
|
||||
|
||||
class TransactionForm(ModelForm):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue