From 25482790dc99cb63246ceb4adaea307116e93161 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 20 May 2022 21:33:06 +0200 Subject: [PATCH] Remove category tree --- ...ions_alter_transaction_options_and_more.py | 56 +++++++++++++++++++ nummi/main/models.py | 26 ++------- nummi/main/static/css/index.css | 7 +-- nummi/main/static/css/main.css | 10 ++++ nummi/main/templates/main/index.html | 23 +++++--- 5 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 nummi/main/migrations/0007_alter_category_options_alter_transaction_options_and_more.py diff --git a/nummi/main/migrations/0007_alter_category_options_alter_transaction_options_and_more.py b/nummi/main/migrations/0007_alter_category_options_alter_transaction_options_and_more.py new file mode 100644 index 0000000..f4baaee --- /dev/null +++ b/nummi/main/migrations/0007_alter_category_options_alter_transaction_options_and_more.py @@ -0,0 +1,56 @@ +# Generated by Django 4.0.4 on 2022-05-20 19:25 + +import django.core.validators +from django.db import migrations, models +import re + + +class Migration(migrations.Migration): + + dependencies = [ + ("main", "0006_alter_category_options_transaction_trader_and_more"), + ] + + operations = [ + migrations.AlterModelOptions( + name="category", + options={}, + ), + migrations.AlterModelOptions( + name="transaction", + options={"ordering": ["-date"]}, + ), + migrations.RemoveField( + model_name="category", + name="full_name", + ), + migrations.RemoveField( + model_name="category", + name="parent", + ), + migrations.AlterField( + model_name="category", + name="name", + field=models.CharField( + default="New Category", + max_length=64, + validators=[ + django.core.validators.RegexValidator( + re.compile("^[-\\w]+\\Z"), + "Enter a valid “slug” consisting of Unicode letters, numbers, underscores, or hyphens.", + "invalid", + ) + ], + ), + ), + migrations.AlterField( + model_name="invoice", + name="name", + field=models.CharField(default="New Invoice", max_length=256), + ), + migrations.AlterField( + model_name="transaction", + name="name", + field=models.CharField(default="New Transaction", max_length=256), + ), + ] diff --git a/nummi/main/models.py b/nummi/main/models.py index b6e57d9..3d7fd3a 100644 --- a/nummi/main/models.py +++ b/nummi/main/models.py @@ -7,35 +7,21 @@ from django.core.validators import validate_unicode_slug, FileExtensionValidator class Category(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) - name = models.CharField(max_length=64, validators=[validate_unicode_slug], default="New Category") - full_name = models.CharField(max_length=512, editable=False, default="") - parent = models.ForeignKey("self", on_delete=models.SET_NULL, blank=True, null=True) + name = models.CharField( + max_length=64, validators=[validate_unicode_slug], default="New Category" + ) def __str__(self): - if self.parent is None or self.parent == self: - return self.name - return f"{self.parent}>{self.name}" - - def save(self, *args, **kwargs): - self.full_name = str(self) - super().save(*args, **kwargs) - for child in self.__class__.objects.filter(parent=self): - child.save() - - @property - def tree(self): - if self.parent is None or self.parent == self: - return [self.name] - return self.parent.tree + [self.name] + return self.name class Meta: - ordering = ["full_name"] + ordering = ["name"] class CategoryForm(ModelForm): class Meta: model = Category - fields = ["name", "parent"] + fields = ["name"] class Transaction(models.Model): diff --git a/nummi/main/static/css/index.css b/nummi/main/static/css/index.css index 6e3addd..4d1cfd5 100644 --- a/nummi/main/static/css/index.css +++ b/nummi/main/static/css/index.css @@ -47,9 +47,6 @@ h1 { text-overflow: ellipsis; } -ul#categories { - list-style-type: "– "; +#categories > a { + margin-right: 1em; } -ul#categories li.cat2 {margin-left: 1em} -ul#categories li.cat3 {margin-left: 2em} -ul#categories li.cat4 {margin-left: 3em} diff --git a/nummi/main/static/css/main.css b/nummi/main/static/css/main.css index bd1652d..01b691b 100644 --- a/nummi/main/static/css/main.css +++ b/nummi/main/static/css/main.css @@ -18,8 +18,18 @@ body { --text-inv: #ffffffde; --bg-01: #dedede; + + --text-link: #0066ff; } h1 { margin: 0; } + +a { + color: var(--text-link); + text-decoration: none; +} +a:hover { + text-decoration: underline; +} diff --git a/nummi/main/templates/main/index.html b/nummi/main/templates/main/index.html index 89db979..3c7b3ef 100644 --- a/nummi/main/templates/main/index.html +++ b/nummi/main/templates/main/index.html @@ -25,7 +25,15 @@ {{ trans.name }} {{ trans.value|floatformat:"2g" }} € {{ trans.trader|default_if_none:"–" }} - {% if trans.category %}{{ trans.category.tree|join:" → " }}{% else %}–{% endif %} + + {% if trans.category %} + + {{ trans.category }} + + {% else %} + – + {% endif %} + {{ trans.description }} {% endfor %} @@ -33,15 +41,14 @@ {% endif %} {% if categories %} - + {% endspaceless %} + {% endif %} {% endblock %}