Add transaction creation
This commit is contained in:
parent
6ef5a441e1
commit
eddfa4708f
2 changed files with 13 additions and 5 deletions
|
@ -4,6 +4,7 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path("", views.index, name="index"),
|
||||
path("transaction", views.transaction, name="transaction"),
|
||||
path("transaction/<uuid>", views.transaction, name="transaction"),
|
||||
path(
|
||||
"transaction/<uuid>/update", views.update_transaction, name="update_transaction"
|
||||
|
|
|
@ -6,14 +6,18 @@ from .models import Transaction, TransactionForm, Invoice, InvoiceForm
|
|||
|
||||
|
||||
def index(request):
|
||||
_transactions = Transaction.objects.order_by("date")[:5]
|
||||
_transactions = Transaction.objects.order_by("-date")[:5]
|
||||
context = {
|
||||
"transactions": _transactions,
|
||||
}
|
||||
return render(request, "main/index.html", context)
|
||||
|
||||
|
||||
def transaction(request, uuid):
|
||||
def transaction(request, uuid=None):
|
||||
if uuid is None:
|
||||
_transaction = Transaction()
|
||||
_invoices = []
|
||||
else:
|
||||
_transaction = get_object_or_404(Transaction, id=uuid)
|
||||
_invoices = Invoice.objects.filter(transaction=_transaction)
|
||||
return render(
|
||||
|
@ -29,7 +33,10 @@ def transaction(request, uuid):
|
|||
|
||||
|
||||
def update_transaction(request, uuid):
|
||||
_transaction = get_object_or_404(Transaction, id=uuid)
|
||||
try:
|
||||
_transaction = Transaction.objects.get(id=uuid)
|
||||
except Transaction.DoesNotExist:
|
||||
_transaction = Transaction(id=uuid)
|
||||
_form = TransactionForm(request.POST, instance=_transaction)
|
||||
_form.save()
|
||||
return redirect(transaction, uuid=uuid)
|
||||
|
|
Loading…
Reference in a new issue