From 60002cfdebb60f8c67f056ad5c68d0bd97021b14 Mon Sep 17 00:00:00 2001 From: Gregory Trullemans Date: Tue, 21 Nov 2023 09:10:28 +0100 Subject: [PATCH] Add BMI into heightweith model --- jarvis/followup/models.py | 4 ++++ jarvis/followup/templates/heightweight/list.html | 4 +++- jarvis/followup/views.py | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/jarvis/followup/models.py b/jarvis/followup/models.py index 1b64031..6533ce6 100644 --- a/jarvis/followup/models.py +++ b/jarvis/followup/models.py @@ -511,6 +511,10 @@ class HeightWeight(Seasonisable): ) weight = models.DecimalField(max_digits=4, decimal_places=1, verbose_name="Weight") + @property + def bmi(self): + return self.weight / (self.height * self.height) + def __str__(self): return f"{self.gymnast} : {self.height}/{self.hips_height} - {self.weight}" diff --git a/jarvis/followup/templates/heightweight/list.html b/jarvis/followup/templates/heightweight/list.html index ac0dadd..90d2487 100644 --- a/jarvis/followup/templates/heightweight/list.html +++ b/jarvis/followup/templates/heightweight/list.html @@ -32,6 +32,7 @@ Height Hips height Weight + BMI @@ -47,6 +48,7 @@ {{ heightweight.height }} {{ heightweight.hips_height }} {{ heightweight.weight }} + {{ heightweight.bmi }} {% endfor %} @@ -77,7 +79,7 @@ paging: false, searching: false, ordering: false, - // "bInfo" : false, + "bInfo" : false, }); }); diff --git a/jarvis/followup/views.py b/jarvis/followup/views.py index 0cfd43f..5ab1175 100644 --- a/jarvis/followup/views.py +++ b/jarvis/followup/views.py @@ -1100,16 +1100,16 @@ def heightweight_create_or_update(request, heightweight_id=None, gymnast_id=None send_mail( f"{gymnast} : Nouveau poids/taille enregistré", - f"Un nouveau poids/taille enregistré pour {gymnast} ({date}) : {height}cm / {weight}kg (BMI: {bmi}).", + f"Un nouveau poids/taille enregistré pour {gymnast} ({date}) : {height} cm / {weight} kg (BMI: {bmi}).", settings.EMAIL_HOST_USER, receiver, fail_silently=False, html_message=f"""

Bonjour,

Un nouveau poids/taille enregistré pour {gymnast} pour le {date.strftime('%d %B %Y')} :


Excellente journée