From a3273c13cf50dab9432a93b2ea7578744d0f6d64 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Fri, 20 May 2022 15:33:24 +0200 Subject: [PATCH] Add parent back to categories --- nummi/main/migrations/0001_initial.py | 96 +++++++++++++++---- .../migrations/0002_delete_subcategory.py | 4 +- ...003_category_parent_alter_category_name.py | 29 ++++++ nummi/main/models.py | 1 + nummi/main/views.py | 1 + 5 files changed, 108 insertions(+), 23 deletions(-) create mode 100644 nummi/main/migrations/0003_category_parent_alter_category_name.py diff --git a/nummi/main/migrations/0001_initial.py b/nummi/main/migrations/0001_initial.py index 3d62d2d..1da39e1 100644 --- a/nummi/main/migrations/0001_initial.py +++ b/nummi/main/migrations/0001_initial.py @@ -9,43 +9,97 @@ class Migration(migrations.Migration): initial = True - dependencies = [ - ] + dependencies = [] operations = [ migrations.CreateModel( - name='Category', + name="Category", fields=[ - ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), - ('name', models.CharField(max_length=256)), + ( + "id", + models.UUIDField( + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + ("name", models.CharField(max_length=256)), ], ), migrations.CreateModel( - name='Transaction', + name="Transaction", fields=[ - ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), - ('name', models.CharField(max_length=256)), - ('description', models.TextField()), - ('value', models.DecimalField(decimal_places=2, max_digits=12)), - ('date', models.DateField()), - ('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.category')), + ( + "id", + models.UUIDField( + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + ("name", models.CharField(max_length=256)), + ("description", models.TextField()), + ("value", models.DecimalField(decimal_places=2, max_digits=12)), + ("date", models.DateField()), + ( + "category", + models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="main.category", + ), + ), ], ), migrations.CreateModel( - name='Invoice', + name="Invoice", fields=[ - ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), - ('name', models.CharField(max_length=256)), - ('file', models.FileField(upload_to='invoices/')), - ('transaction', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.transaction')), + ( + "id", + models.UUIDField( + default=uuid.uuid4, + editable=False, + primary_key=True, + serialize=False, + ), + ), + ("name", models.CharField(max_length=256)), + ("file", models.FileField(upload_to="invoices/")), + ( + "transaction", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + to="main.transaction", + ), + ), ], ), migrations.CreateModel( - name='SubCategory', + name="SubCategory", fields=[ - ('category_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='main.category')), - ('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='category_parent', to='main.category')), + ( + "category_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="main.category", + ), + ), + ( + "parent", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, + related_name="category_parent", + to="main.category", + ), + ), ], - bases=('main.category',), + bases=("main.category",), ), ] diff --git a/nummi/main/migrations/0002_delete_subcategory.py b/nummi/main/migrations/0002_delete_subcategory.py index a41e256..4a772ac 100644 --- a/nummi/main/migrations/0002_delete_subcategory.py +++ b/nummi/main/migrations/0002_delete_subcategory.py @@ -6,11 +6,11 @@ from django.db import migrations class Migration(migrations.Migration): dependencies = [ - ('main', '0001_initial'), + ("main", "0001_initial"), ] operations = [ migrations.DeleteModel( - name='SubCategory', + name="SubCategory", ), ] diff --git a/nummi/main/migrations/0003_category_parent_alter_category_name.py b/nummi/main/migrations/0003_category_parent_alter_category_name.py new file mode 100644 index 0000000..cede3ea --- /dev/null +++ b/nummi/main/migrations/0003_category_parent_alter_category_name.py @@ -0,0 +1,29 @@ +# Generated by Django 4.0.4 on 2022-05-20 13:33 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ("main", "0002_delete_subcategory"), + ] + + operations = [ + migrations.AddField( + model_name="category", + name="parent", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="main.category", + ), + ), + migrations.AlterField( + model_name="category", + name="name", + field=models.CharField(max_length=64), + ), + ] diff --git a/nummi/main/models.py b/nummi/main/models.py index cafb07d..ef5a54e 100644 --- a/nummi/main/models.py +++ b/nummi/main/models.py @@ -6,6 +6,7 @@ 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=64) + parent = models.ForeignKey("self", on_delete=models.SET_NULL, blank=True, null=True) def __str__(self): return self.name diff --git a/nummi/main/views.py b/nummi/main/views.py index 06bd679..a3c6ea4 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -22,6 +22,7 @@ class LoginView(auth_views.LoginView): template_name = "main/login.html" next_page = "index" + class LogoutView(auth_views.LogoutView): next_page = "login"