Add parent back to categories

This commit is contained in:
Edgar P. Burkhart 2022-05-20 15:33:24 +02:00
parent 83937b4103
commit a3273c13cf
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
5 changed files with 108 additions and 23 deletions

View file

@ -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",),
),
]

View file

@ -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",
),
]

View file

@ -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),
),
]

View file

@ -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

View file

@ -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"