quantity fields in food log and recipe upload drop zone
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user