Use list view
This commit is contained in:
parent
69c55f0cce
commit
fbff835598
3 changed files with 10 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
<a href="{% url 'index' %}">Home</a>
|
<a href="{% url 'index' %}">Home</a>
|
||||||
|
|
||||||
|
<h1>{{ transaction }}</h1>
|
||||||
<form action="{% url 'update_transaction' transaction.id %}" method="post">
|
<form action="{% url 'update_transaction' transaction.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form }}
|
{{ form }}
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django.urls import path
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
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("transaction/<uuid>", views.transaction, name="transaction"),
|
path("transaction/<uuid>", views.transaction, name="transaction"),
|
||||||
path(
|
path(
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
from django.views import generic
|
||||||
|
|
||||||
|
|
||||||
from .models import Transaction, TransactionForm, Invoice, InvoiceForm
|
from .models import Transaction, TransactionForm, Invoice, InvoiceForm
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class IndexView(generic.ListView):
|
||||||
_transactions = Transaction.objects.order_by("-date")[:5]
|
template_name = "main/index.html"
|
||||||
context = {
|
context_object_name = "transactions"
|
||||||
"transactions": _transactions,
|
|
||||||
}
|
def get_queryset(self):
|
||||||
return render(request, "main/index.html", context)
|
return Transaction.objects.order_by("-date")[:5]
|
||||||
|
|
||||||
|
|
||||||
def transaction(request, uuid=None):
|
def transaction(request, uuid=None):
|
||||||
|
|
Loading…
Reference in a new issue