Self hosted FLOSS fitness/workout, nutrition and weight tracker
Update the user's last weight entry when needed
Roland Geiderbb320e560807
diff --git a/wger/manager/models.py b/wger/manager/models.pyindex e14fe64d1..1fff731aa 100644--- a/wger/manager/models.py+++ b/wger/manager/models.py@@ -689,7 +689,7 @@ by the US Department of Agriculture. It is extremely complete, with around- weight in kg- height in m'''- return self.weight / (self.height/100.0 * self.height/100.0)+ return self.weight / (self.height / 100.0 * self.height / 100.0)def calculate_basal_metabolic_rate(self, formula=1):'''diff --git a/wger/nutrition/views/bmi.py b/wger/nutrition/views/bmi.pyindex 4e988fbfc..2e7fa86ac 100644--- a/wger/nutrition/views/bmi.py+++ b/wger/nutrition/views/bmi.py@@ -63,13 +63,20 @@ def calculate(request):# Create a new weight entry as neededif (not WeightEntry.objects.all().exists()- or (datetime.date.today() - WeightEntry.objects.all().latest().creation_date > datetime.timedelta(7))):+ or (datetime.date.today() - WeightEntry.objects.all().latest().creation_date+ > datetime.timedelta(1))):entry = WeightEntry()entry.weight = form.cleaned_data['weight']entry.user = request.userentry.creation_date = datetime.date.today()entry.save()+ # Update the last entry+ else:+ entry = WeightEntry.objects.all().latest()+ entry.weight = form.cleaned_data['weight']+ entry.save()+bmi = request.user.userprofile.calculate_bmi()result = {'bmi': '{0:.2f}'.format(bmi)}data = json.dumps(result)