diff --git a/nummi/main/migrations/0004_alter_category_options_category_full_name.py b/nummi/main/migrations/0004_alter_category_options_category_full_name.py index 931edf6..1af43dd 100644 --- a/nummi/main/migrations/0004_alter_category_options_category_full_name.py +++ b/nummi/main/migrations/0004_alter_category_options_category_full_name.py @@ -6,18 +6,18 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('main', '0003_category_parent_alter_category_name'), + ("main", "0003_category_parent_alter_category_name"), ] operations = [ migrations.AlterModelOptions( - name='category', - options={'ordering': ['-parent_id', 'name']}, + name="category", + options={"ordering": ["-parent_id", "name"]}, ), migrations.AddField( - model_name='category', - name='full_name', - field=models.CharField(default='', max_length=512), + model_name="category", + name="full_name", + field=models.CharField(default="", max_length=512), preserve_default=False, ), ] diff --git a/nummi/main/migrations/0005_alter_category_full_name.py b/nummi/main/migrations/0005_alter_category_full_name.py index c52a980..af9449f 100644 --- a/nummi/main/migrations/0005_alter_category_full_name.py +++ b/nummi/main/migrations/0005_alter_category_full_name.py @@ -6,13 +6,13 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('main', '0004_alter_category_options_category_full_name'), + ("main", "0004_alter_category_options_category_full_name"), ] operations = [ migrations.AlterField( - model_name='category', - name='full_name', - field=models.CharField(default='', editable=False, max_length=512), + model_name="category", + name="full_name", + field=models.CharField(default="", editable=False, max_length=512), ), ] diff --git a/nummi/main/models.py b/nummi/main/models.py index a218d1a..13b9c82 100644 --- a/nummi/main/models.py +++ b/nummi/main/models.py @@ -1,16 +1,18 @@ import uuid from django.db import models from django.forms import ModelForm +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) + name = models.CharField(max_length=64, validators=[validate_unicode_slug]) full_name = models.CharField(max_length=512, editable=False, default="") parent = models.ForeignKey("self", on_delete=models.SET_NULL, blank=True, null=True) def __str__(self): - if self.parent is None: return self.name + if self.parent is None: + return self.name return f"{self.parent}>{self.name}" def save(self, *args, **kwargs): @@ -20,7 +22,7 @@ class Category(models.Model): child.save() class Meta: - ordering = ['full_name'] + ordering = ["full_name"] class Transaction(models.Model): @@ -49,7 +51,9 @@ class TransactionForm(ModelForm): class Invoice(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=256) - file = models.FileField(upload_to="invoices/") + file = models.FileField( + upload_to="invoices/", validators=[FileExtensionValidator(["pdf"])] + ) transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE) def __str__(self): diff --git a/nummi/main/views.py b/nummi/main/views.py index 8d20f80..95bef5e 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -15,7 +15,8 @@ def index(request): children = [] for child in Category.objects.filter(parent=cat): children += _cat_list(child) - if len(children) == 0: return cat.name, + if len(children) == 0: + return (cat.name,) return cat.name, children _cats = []