Use list view

This commit is contained in:
Edgar P. Burkhart 2022-05-19 21:47:02 +02:00
parent 69c55f0cce
commit fbff835598
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
3 changed files with 10 additions and 7 deletions

View file

@ -1,5 +1,6 @@
<a href="{% url 'index' %}">Home</a>
<h1>{{ transaction }}</h1>
<form action="{% url 'update_transaction' transaction.id %}" method="post">
{% csrf_token %}
{{ form }}

View file

@ -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/<uuid>", views.transaction, name="transaction"),
path(

View file

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