From 57bd930907122549999a3c76c211b43777fbaaf7 Mon Sep 17 00:00:00 2001 From: gw3000 Date: Fri, 14 Jul 2023 19:09:07 +0200 Subject: [PATCH] costs sum works in view fallenbirds --- app/bird/models.py | 3 --- app/bird/templates/bird/bird_all.html | 2 +- app/bird/views.py | 3 ++- app/costs/forms.py | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/bird/models.py b/app/bird/models.py index 76d724a..603ec7a 100644 --- a/app/bird/models.py +++ b/app/bird/models.py @@ -28,9 +28,6 @@ class FallenBird(models.Model): diagnostic_finding = models.CharField( max_length=256, verbose_name=_("Diagnose bei Fund") ) - # costs = models.DecimalField( - # max_digits=5, decimal_places=2, default="0.00", verbose_name=_("Kosten") - # ) rescuer = models.ForeignKey( Rescuer, on_delete=models.SET_NULL, diff --git a/app/bird/templates/bird/bird_all.html b/app/bird/templates/bird/bird_all.html index 535efc3..945694a 100644 --- a/app/bird/templates/bird/bird_all.html +++ b/app/bird/templates/bird/bird_all.html @@ -66,7 +66,7 @@ {{ bird.place }} {{ bird.status }} {{ bird.aviary|default_if_none:"" }} - {{ bird.costs }} + {{ bird.total_costs |default_if_none:"0,00" }} € {% endfor %} diff --git a/app/bird/views.py b/app/bird/views.py index ecd758b..81076a0 100644 --- a/app/bird/views.py +++ b/app/bird/views.py @@ -1,4 +1,5 @@ import names +from django.db.models import Sum from django.contrib.auth.decorators import login_required from django.shortcuts import HttpResponse, redirect, render from rescuer.models import Rescuer @@ -42,7 +43,7 @@ def bird_help(request): @login_required(login_url="account_login") def bird_all(request): - birds = FallenBird.objects.all() + birds = FallenBird.objects.all().annotate(total_costs=Sum('costs__costs')) rescuer_modal = Rescuer.objects.all() context = {"birds": birds, "rescuer_modal": rescuer_modal} # Post came from the modal form. diff --git a/app/costs/forms.py b/app/costs/forms.py index 2c073fb..53810b8 100644 --- a/app/costs/forms.py +++ b/app/costs/forms.py @@ -23,7 +23,7 @@ class CostsForm(forms.ModelForm): ] labels = { "id_bird": _("Patient"), - "costs": _("Betrag"), + "costs": _("Betrag [€]"), "comment": _("Bemerkung"), "created": _("Gebucht am"), }