quantity fields in food log and recipe upload drop zone

This commit is contained in:
Joren de Graaf
2026-10-15 20:35:56 +02:00
parent f36f05b9bc
commit 86e3afaca7
25 changed files with 420 additions and 67 deletions
+8
View File
@@ -1,4 +1,5 @@
import uuid
from decimal import Decimal
from django.conf import settings
from django.core.exceptions import ValidationError
@@ -79,6 +80,8 @@ class FoodLogEntry(models.Model):
barcode_snapshot = models.CharField(max_length=64, blank=True)
portion_label_snapshot = models.CharField(max_length=100, blank=True)
amount = models.DecimalField(max_digits=10, decimal_places=3, validators=POSITIVE)
quantity = models.DecimalField(max_digits=7, decimal_places=2, default=1,
validators=[MinValueValidator(Decimal('0.01'))])
unit = models.CharField(max_length=8, choices=[*Unit.choices, ('servings', 'servings')])
beverage_volume_ml = models.DecimalField(max_digits=10, decimal_places=3, null=True, blank=True, validators=NON_NEGATIVE)
hydration_amount_ml = models.DecimalField(max_digits=10, decimal_places=3, default=0, validators=NON_NEGATIVE)
@@ -99,6 +102,11 @@ class FoodLogEntry(models.Model):
class Meta:
ordering = ('date', 'time', 'pk')
constraints = [models.CheckConstraint(condition=Q(quantity__gt=0), name='food_positive_log_quantity')]
def effective_nutrient(self, name):
value = getattr(self, name)
return value * self.quantity if value is not None else None
def clean(self):
super().clean()