Add delete button to transaction form

This commit is contained in:
Edgar P. Burkhart 2022-05-22 13:27:57 +02:00
parent df0882bd88
commit 83aefe1f84
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
3 changed files with 9 additions and 0 deletions

View file

@ -18,6 +18,7 @@
{{ field }} {{ field }}
{% endfor %} {% endfor %}
<div class="buttons"> <div class="buttons">
<a href="{% url 'del_transaction' transaction.id %}"><input type="button" value="Delete" /></a>
<input type="reset" /> <input type="reset" />
<input type="submit" value="Save Transaction" /> <input type="submit" value="Save Transaction" />
</div> </div>

View file

@ -11,6 +11,7 @@ urlpatterns = [
path( path(
"transaction/<uuid>/update", views.update_transaction, name="update_transaction" "transaction/<uuid>/update", views.update_transaction, name="update_transaction"
), ),
path("transaction/<uuid>/del", views.del_transaction, name="del_transaction"),
path("transaction/<uuid>/add_invoice", views.add_invoice, name="add_invoice"), path("transaction/<uuid>/add_invoice", views.add_invoice, name="add_invoice"),
path( path(
"transaction/<uuid>/del_invoice/<invoice_id>", "transaction/<uuid>/del_invoice/<invoice_id>",

View file

@ -66,6 +66,13 @@ def update_transaction(request, uuid):
return redirect(transaction, uuid=uuid) return redirect(transaction, uuid=uuid)
@login_required
def del_transaction(request, uuid):
_transaction = get_object_or_404(Transaction, id=uuid)
_transaction.delete()
return redirect(index)
@login_required @login_required
def invoice(request, uuid): def invoice(request, uuid):
_invoice = get_object_or_404(Invoice, id=uuid) _invoice = get_object_or_404(Invoice, id=uuid)