Single layer of categories
This commit is contained in:
parent
36be624f5c
commit
e38b781ff9
7 changed files with 69 additions and 80 deletions
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.0.4 on 2022-05-19 14:02
|
||||
# Generated by Django 4.0.4 on 2022-05-20 12:24
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -9,48 +9,43 @@ class Migration(migrations.Migration):
|
|||
|
||||
initial = True
|
||||
|
||||
dependencies = []
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Transaction",
|
||||
name='Category',
|
||||
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()),
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=256)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="Invoice",
|
||||
name='Transaction',
|
||||
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)),
|
||||
('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',
|
||||
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')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
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')),
|
||||
],
|
||||
bases=('main.category',),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
# Generated by Django 4.0.4 on 2022-05-20 11:34
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Category',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=256)),
|
||||
('parent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.category')),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='transaction',
|
||||
name='category',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='main.category'),
|
||||
),
|
||||
]
|
16
nummi/main/migrations/0002_delete_subcategory.py
Normal file
16
nummi/main/migrations/0002_delete_subcategory.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Generated by Django 4.0.4 on 2022-05-20 12:30
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.DeleteModel(
|
||||
name='SubCategory',
|
||||
),
|
||||
]
|
|
@ -5,14 +5,10 @@ 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=256)
|
||||
parent = models.ForeignKey("self", on_delete=models.SET_NULL, blank=True, null=True)
|
||||
name = models.CharField(max_length=64)
|
||||
|
||||
def __str__(self):
|
||||
if self.parent:
|
||||
return f"{self.parent}>{self.name}"
|
||||
else:
|
||||
return f"{self.name}"
|
||||
return self.name
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
|
@ -35,7 +31,7 @@ class Transaction(models.Model):
|
|||
class TransactionForm(ModelForm):
|
||||
class Meta:
|
||||
model = Transaction
|
||||
fields = ["name", "description", "value", "date"]
|
||||
fields = ["name", "description", "value", "date", "category"]
|
||||
|
||||
|
||||
class Invoice(models.Model):
|
||||
|
|
|
@ -12,4 +12,13 @@
|
|||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% if categories %}
|
||||
<ul>
|
||||
{% for cat in categories %}
|
||||
<li>{{ cat }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.urls import path
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.IndexView.as_view(), name="index"),
|
||||
path("", views.index, name="index"),
|
||||
path("transaction", views.transaction, name="transaction"),
|
||||
path("transaction/<uuid>", views.transaction, name="transaction"),
|
||||
path(
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.http import HttpResponse
|
||||
from django.views import generic
|
||||
|
||||
from .models import Transaction, TransactionForm, Invoice, InvoiceForm, Category
|
||||
|
||||
|
||||
from .models import Transaction, TransactionForm, Invoice, InvoiceForm
|
||||
def index(request):
|
||||
_transactions = Transaction.objects.order_by("-date")[:5]
|
||||
_categories = Category.objects.order_by("name")
|
||||
|
||||
|
||||
class IndexView(generic.ListView):
|
||||
template_name = "main/index.html"
|
||||
context_object_name = "transactions"
|
||||
|
||||
def get_queryset(self):
|
||||
return Transaction.objects.order_by("-date")[:5]
|
||||
context = {
|
||||
"transactions": _transactions,
|
||||
"categories": _categories,
|
||||
}
|
||||
return render(request, "main/index.html", context)
|
||||
|
||||
|
||||
def transaction(request, uuid=None):
|
||||
|
|
Loading…
Reference in a new issue