diff --git a/nummi/main/templates/main/index.html b/nummi/main/templates/main/index.html
index 70888b0..4f69d4b 100644
--- a/nummi/main/templates/main/index.html
+++ b/nummi/main/templates/main/index.html
@@ -31,9 +31,7 @@
{% if categories %}
- {% for cat in categories %}
- - {{ cat }}
- {% endfor %}
+ {{ categories|unordered_list }}
{% endif %}
diff --git a/nummi/main/views.py b/nummi/main/views.py
index a3c6ea4..ee8960a 100644
--- a/nummi/main/views.py
+++ b/nummi/main/views.py
@@ -9,11 +9,22 @@ from .models import Transaction, TransactionForm, Invoice, InvoiceForm, Category
@login_required
def index(request):
_transactions = Transaction.objects.order_by("-date")[:5]
- _categories = Category.objects.order_by("name")
+ _categories = Category.objects.filter(parent=None).order_by("name")
+
+ def _cat_list(cat):
+ children = []
+ for child in Category.objects.filter(parent=cat):
+ children += _cat_list(child)
+ if len(children) == 0: return cat,
+ return cat, children
+
+ _cats = []
+ for cat in _categories:
+ _cats += _cat_list(cat)
context = {
"transactions": _transactions,
- "categories": _categories,
+ "categories": _cats,
}
return render(request, "main/index.html", context)