food logger context tips
This commit is contained in:
@@ -35,6 +35,8 @@ class FoodProduct(models.Model):
|
||||
brand = models.CharField(max_length=255, blank=True)
|
||||
image_url = models.URLField(blank=True)
|
||||
package_quantity = models.CharField(max_length=100, blank=True)
|
||||
package_amount = models.DecimalField(max_digits=10, decimal_places=3, null=True, blank=True, validators=POSITIVE)
|
||||
package_unit = models.CharField(max_length=2, choices=Unit.choices, blank=True)
|
||||
serving_size_text = models.CharField(max_length=100, blank=True)
|
||||
serving_amount = models.DecimalField(max_digits=10, decimal_places=3, null=True, blank=True, validators=POSITIVE)
|
||||
serving_unit = models.CharField(max_length=2, choices=Unit.choices, blank=True)
|
||||
@@ -169,6 +171,7 @@ class KitchenInventoryItem(models.Model):
|
||||
category = models.ForeignKey(InventoryCategory, on_delete=models.PROTECT, null=True, blank=True)
|
||||
notes = models.TextField(blank=True)
|
||||
opened = models.BooleanField(default=False)
|
||||
remaining_amount = models.DecimalField(max_digits=10, decimal_places=3, null=True, blank=True, validators=NON_NEGATIVE)
|
||||
best_before = models.DateField(null=True, blank=True)
|
||||
archived_at = models.DateTimeField(null=True, blank=True)
|
||||
added_at = models.DateTimeField(auto_now_add=True)
|
||||
@@ -176,6 +179,10 @@ class KitchenInventoryItem(models.Model):
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if self.remaining_amount is not None and (not self.product_id or self.quantity != 1 or not self.opened or
|
||||
not self.product.package_amount or
|
||||
self.remaining_amount > self.product.package_amount):
|
||||
raise ValidationError({'remaining_amount': 'Remaining contents require one opened package with a known package size.'})
|
||||
if self.user_id and self.product_id and self.product.owner_id != self.user_id:
|
||||
raise ValidationError({'product': 'Choose one of your own products.'})
|
||||
if self.user_id and self.location_id and self.location.user_id != self.user_id:
|
||||
|
||||
Reference in New Issue
Block a user