Homepage, transaction page and invoice

This commit is contained in:
Edgar P. Burkhart 2022-05-19 18:51:53 +02:00
parent a0f4e5ae54
commit 08868ce7c6
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
7 changed files with 50 additions and 4 deletions

Binary file not shown.

BIN
nummi/invoices/artha.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 481 KiB

View file

@ -1,3 +1,6 @@
from django.contrib import admin
# Register your models here.
from .models import Transaction, Invoice
admin.site.register(Transaction)
admin.site.register(Invoice)

View file

@ -0,0 +1,7 @@
{% if transactions %}
<ul>
{% for trans in transactions %}
<li><a href="transaction/{{ trans.id }}">{{ trans }}</a></li>
{% endfor %}
</ul>
{% endif %}

View file

@ -0,0 +1,6 @@
<h1>{{ transaction }}</h1>
<ul>
{% for inv in invoices %}
<li><a href="../invoice/{{ inv.id }}">{{ inv.name }}</a></li>
{% endfor %}
</ul>

View file

@ -2,4 +2,8 @@ from django.urls import path
from . import views
urlpatterns = [path("", views.index, name="index")]
urlpatterns = [
path("", views.index, name="index"),
path("transaction/<uuid>", views.transaction, name="transaction"),
path("invoice/<uuid>", views.invoice, name="invoice"),
]

View file

@ -1,6 +1,32 @@
from django.shortcuts import render
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from .models import Transaction, Invoice
def index(request):
return HttpResponse("Hello world!")
_transactions = Transaction.objects.order_by("date")[:5]
context = {
"transactions": _transactions,
}
return render(request, "main/index.html", context)
def transaction(request, uuid):
_transaction = get_object_or_404(Transaction, id=uuid)
_invoices = Invoice.objects.filter(transaction=_transaction)
return render(
request,
"main/transaction.html",
{
"transaction": _transaction,
"invoices": _invoices,
},
)
def invoice(request, uuid):
_invoice = get_object_or_404(Invoice, id=uuid)
with _invoice.file.open() as _file:
return HttpResponse(_file.read(), content_type="application/pdf")