costs now in json format
This commit is contained in:
parent
826a9ff517
commit
6e642a9785
5 changed files with 24 additions and 9 deletions
|
@ -43,7 +43,7 @@ class BirdEditForm(forms.ModelForm):
|
|||
"place",
|
||||
"status",
|
||||
"aviary",
|
||||
"cost_sum",
|
||||
# "cost_sum",
|
||||
# "rescuer",
|
||||
]
|
||||
labels = {
|
||||
|
@ -52,6 +52,6 @@ class BirdEditForm(forms.ModelForm):
|
|||
"place": _("Fundort"),
|
||||
"status": _("Status"),
|
||||
"aviary": _("Voliere"),
|
||||
"cost_sum": _("Kosten der Behandlung [Euro]"),
|
||||
# "cost_sum": _("Kosten der Behandlung [Euro]"),
|
||||
# "rescuer": _("Retter"),
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# Generated by Django 4.2.2 on 2023-07-08 20:30
|
||||
# Generated by Django 4.2.2 on 2023-07-09 11:26
|
||||
|
||||
import bird.models
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -11,9 +12,9 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
("rescuer", "0001_initial"),
|
||||
("aviary", "0002_alter_aviary_condition"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("aviary", "0002_alter_aviary_condition"),
|
||||
("rescuer", "0001_initial"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
@ -82,8 +83,10 @@ class Migration(migrations.Migration):
|
|||
),
|
||||
("diagnostic_finding", models.CharField(max_length=256)),
|
||||
(
|
||||
"cost_sum",
|
||||
models.DecimalField(decimal_places=2, default=0.0, max_digits=5),
|
||||
"costs",
|
||||
models.JSONField(
|
||||
default=bird.models.costs_default, verbose_name="Costs"
|
||||
),
|
||||
),
|
||||
(
|
||||
"aviary",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from uuid import uuid4
|
||||
from datetime import date
|
||||
|
||||
from aviary.models import Aviary
|
||||
from django.conf import settings
|
||||
|
@ -6,6 +7,8 @@ from django.db import models
|
|||
from django.utils.translation import gettext_lazy as _
|
||||
from rescuer.models import Rescuer
|
||||
|
||||
def costs_default():
|
||||
return [{"date": date.today().strftime("%Y-%m-%d"), "cost_entry": "0.00"}]
|
||||
|
||||
class FallenBird(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
|
@ -18,7 +21,7 @@ class FallenBird(models.Model):
|
|||
created = models.DateTimeField(auto_now_add=True, verbose_name=_("angelegt am"))
|
||||
updated = models.DateTimeField(auto_now=True, verbose_name=_("geändert am"))
|
||||
diagnostic_finding = models.CharField(max_length=256)
|
||||
cost_sum = models.DecimalField(max_digits=5, decimal_places=2, default=0.00)
|
||||
costs = models.JSONField("Costs", default=costs_default)
|
||||
rescuer = models.ForeignKey(
|
||||
Rescuer, on_delete=models.SET_NULL, blank=True, null=True
|
||||
)
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
<td>{{ bird.date_found }}</td>
|
||||
<td>{{ bird.status }}</td>
|
||||
<td>{{ bird.aviary|default_if_none:"" }}</td>
|
||||
<td>{{ bird.cost_sum }} €</td>
|
||||
<td>{{ bird.costs }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -41,6 +41,15 @@ def bird_help(request):
|
|||
@login_required(login_url="account_login")
|
||||
def bird_all(request):
|
||||
birds = FallenBird.objects.all()
|
||||
# Sum all costs per bird from json
|
||||
for bird in birds:
|
||||
costs_per_bird = float()
|
||||
for item in bird.costs:
|
||||
costs_per_bird += float(item['cost_entry'])
|
||||
if costs_per_bird == 0.0:
|
||||
costs_per_bird = ""
|
||||
bird.costs = costs_per_bird
|
||||
|
||||
rescuer_modal = Rescuer.objects.all()
|
||||
context = {"birds": birds, "rescuer_modal": rescuer_modal}
|
||||
# Post came from the modal form.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue