diff --git a/nummi/main/templates/main/transaction.html b/nummi/main/templates/main/transaction.html index 8fbda93..efec694 100644 --- a/nummi/main/templates/main/transaction.html +++ b/nummi/main/templates/main/transaction.html @@ -1,5 +1,6 @@ Home +

{{ transaction }}

{% csrf_token %} {{ form }} diff --git a/nummi/main/urls.py b/nummi/main/urls.py index 1c114be..45a0bf5 100644 --- a/nummi/main/urls.py +++ b/nummi/main/urls.py @@ -3,7 +3,7 @@ from django.urls import path from . import views urlpatterns = [ - path("", views.index, name="index"), + path("", views.IndexView.as_view(), name="index"), path("transaction", views.transaction, name="transaction"), path("transaction/", views.transaction, name="transaction"), path( diff --git a/nummi/main/views.py b/nummi/main/views.py index 91c4604..619b9c2 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -1,15 +1,17 @@ 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 -def index(request): - _transactions = Transaction.objects.order_by("-date")[:5] - context = { - "transactions": _transactions, - } - return render(request, "main/index.html", context) +class IndexView(generic.ListView): + template_name = "main/index.html" + context_object_name = "transactions" + + def get_queryset(self): + return Transaction.objects.order_by("-date")[:5] def transaction(request, uuid=None):