From c06acb284acdac7ed43718c440b034818d402972 Mon Sep 17 00:00:00 2001 From: gw3000 Date: Thu, 13 Jul 2023 23:48:50 +0200 Subject: [PATCH] costs should work so far --- app/costs/models.py | 2 +- app/costs/templates/costs/costs_all.html | 2 +- app/costs/templates/costs/costs_create.html | 41 +++++++++++++++++++++ app/costs/templates/costs/costs_delete.html | 3 -- app/costs/templates/costs/costs_edit.html | 3 -- app/costs/views.py | 28 ++++++++------ 6 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 app/costs/templates/costs/costs_create.html diff --git a/app/costs/models.py b/app/costs/models.py index 8ff8ecb..b55a1e8 100644 --- a/app/costs/models.py +++ b/app/costs/models.py @@ -22,7 +22,7 @@ class Costs(models.Model): decimal_places=2, default="0.00", verbose_name=_("Betrag")) - created = models.DateTimeField( + created = models.DateField( verbose_name=_("Gebucht am")) comment = models.CharField( max_length=512, diff --git a/app/costs/templates/costs/costs_all.html b/app/costs/templates/costs/costs_all.html index 38ae578..610d937 100644 --- a/app/costs/templates/costs/costs_all.html +++ b/app/costs/templates/costs/costs_all.html @@ -63,7 +63,7 @@ {{item.id_bird}} {{item.costs}} {{item.created}} - {{item.comment}} + {{item.comment|default_if_none:""}} {{item.user}} diff --git a/app/costs/templates/costs/costs_create.html b/app/costs/templates/costs/costs_create.html new file mode 100644 index 0000000..c2ea0a9 --- /dev/null +++ b/app/costs/templates/costs/costs_create.html @@ -0,0 +1,41 @@ +{% extends "base.html" %} +{% load static %} +{% load crispy_forms_tags %} +{% block content %} +

Buchung anlegen

+

+
+
+
+
+ {% csrf_token %} + {{form|crispy}} + + +
+
+
+ +
+

+ Kennung +

+

+ Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Reiciendis, hic enim pariatur, exercitationem, repellat quasi sit + temporibus dicta voluptate in voluptates. Alias deserunt sint + suscipit explicabo et. Perferendis, dolor praesentium. +

+

+ Vogel +

+

+ Lorem ipsum dolor sit, amet consectetur adipisicing elit. + Reiciendis, hic enim pariatur, exercitationem, repellat quasi sit + temporibus dicta voluptate in voluptates. Alias deserunt sint + suscipit explicabo et. Perferendis, dolor praesentium. +

+ +
+
+{% endblock content %} \ No newline at end of file diff --git a/app/costs/templates/costs/costs_delete.html b/app/costs/templates/costs/costs_delete.html index 1dac872..210ed21 100644 --- a/app/costs/templates/costs/costs_delete.html +++ b/app/costs/templates/costs/costs_delete.html @@ -49,7 +49,4 @@ - - - {% endblock content %} \ No newline at end of file diff --git a/app/costs/templates/costs/costs_edit.html b/app/costs/templates/costs/costs_edit.html index 784f87e..50be813 100644 --- a/app/costs/templates/costs/costs_edit.html +++ b/app/costs/templates/costs/costs_edit.html @@ -38,7 +38,4 @@ - - - {% endblock content %} \ No newline at end of file diff --git a/app/costs/views.py b/app/costs/views.py index 7c32893..1366115 100644 --- a/app/costs/views.py +++ b/app/costs/views.py @@ -3,6 +3,7 @@ from django.shortcuts import render, redirect from .models import Costs from .forms import CostsForm + @login_required(login_url="account_login") def costs_all(request): costs = Costs.objects.all() @@ -10,6 +11,20 @@ def costs_all(request): return render(request, "costs/costs_all.html", context) +@login_required(login_url="account_login") +def costs_create(request): + if request.method == "POST": + form = CostsForm(request.POST or None) + if form.is_valid(): + fs = form.save(commit=False) + fs.user = request.user + fs.save() + return redirect("costs_all") + form = CostsForm() + context = {"form": form} + return render(request, "costs/costs_create.html", context) + + @login_required(login_url="account_login") def costs_edit(request, id): costs = Costs.objects.get(id=id) @@ -22,23 +37,12 @@ def costs_edit(request, id): context = {"costs": costs, "form": form} return render(request, "costs/costs_edit.html", context) + @login_required(login_url="account_login") def costs_delete(request, id): costs = Costs.objects.get(id=id) - form = CostsForm(request.POST or None, instance=costs) if request.method == "POST": costs.delete() return redirect("costs_all") context = {"costs": costs} return render(request, "costs/costs_delete.html", context) - -@login_required(login_url="account_login") -def costs_create(request): - form = CostsForm() - if request.method == "POST": - form = CostsForm(request.POST or None) - if form.is_valid(): - fs = form.save(commit=False) - fs.user = request.user - fs.save() - return render(request, "costs/costs_all.html") \ No newline at end of file