Add category page
This commit is contained in:
parent
df49afb5a4
commit
467c8002e2
6 changed files with 84 additions and 22 deletions
|
@ -12,7 +12,7 @@ class Category(models.Model):
|
|||
parent = models.ForeignKey("self", on_delete=models.SET_NULL, blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
if self.parent is None:
|
||||
if self.parent is None or self.parent == self:
|
||||
return self.name
|
||||
return f"{self.parent}>{self.name}"
|
||||
|
||||
|
@ -24,7 +24,7 @@ class Category(models.Model):
|
|||
|
||||
@property
|
||||
def tree(self):
|
||||
if self.parent is None:
|
||||
if self.parent is None or self.parent == self:
|
||||
return [self.name]
|
||||
return self.parent.tree + [self.name]
|
||||
|
||||
|
@ -32,6 +32,12 @@ class Category(models.Model):
|
|||
ordering = ["full_name"]
|
||||
|
||||
|
||||
class CategoryForm(ModelForm):
|
||||
class Meta:
|
||||
model = Category
|
||||
fields = ["name", "parent"]
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(max_length=256, default="Transaction")
|
||||
|
@ -49,6 +55,9 @@ class Transaction(models.Model):
|
|||
return f"{res} ({self.category})"
|
||||
return res
|
||||
|
||||
class Meta:
|
||||
ordering = ["-date"]
|
||||
|
||||
|
||||
class TransactionForm(ModelForm):
|
||||
class Meta:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue