adding food logging, phase 5
This commit is contained in:
+6
-1
@@ -117,9 +117,14 @@ class FoodPortion(models.Model):
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=('user', 'product', 'label'), name='food_unique_portion_label')]
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=('user', 'product', 'label'), name='food_unique_portion_label'),
|
||||
models.UniqueConstraint(fields=('user', 'product'), condition=Q(is_default=True), name='food_one_default_portion'),
|
||||
]
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if self.product_id and self.user_id and self.product.owner_id != self.user_id:
|
||||
raise ValidationError({'product': 'Choose one of your own food products.'})
|
||||
if self.product_id and self.unit != self.product.base_unit:
|
||||
raise ValidationError({'unit': 'Use the same unit as the product nutrition basis.'})
|
||||
|
||||
Reference in New Issue
Block a user