latest changes

This commit is contained in:
Joren de Graaf
2026-10-07 14:33:21 +02:00
parent 86be3034c8
commit 98f76918dc
27 changed files with 1500 additions and 11 deletions
+48
View File
@@ -128,3 +128,51 @@ class FoodPortion(models.Model):
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.'})
class InventoryLocation(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
sort_order = models.PositiveIntegerField(default=0)
class Meta:
constraints = [models.UniqueConstraint(fields=('user', 'name'), name='food_unique_inventory_location')]
ordering = ('sort_order', 'name')
def __str__(self):
return self.name
class InventoryCategory(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
class Meta:
constraints = [models.UniqueConstraint(fields=('user', 'name'), name='food_unique_inventory_category')]
ordering = ('name',)
def __str__(self):
return self.name
class KitchenInventoryItem(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='kitchen_inventory')
product = models.ForeignKey(FoodProduct, on_delete=models.PROTECT, related_name='inventory_items')
quantity = models.PositiveIntegerField(default=1, validators=[MinValueValidator(1)])
location = models.ForeignKey(InventoryLocation, on_delete=models.PROTECT)
category = models.ForeignKey(InventoryCategory, on_delete=models.PROTECT, null=True, blank=True)
notes = models.TextField(blank=True)
opened = models.BooleanField(default=False)
best_before = models.DateField(null=True, blank=True)
archived_at = models.DateTimeField(null=True, blank=True)
added_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def clean(self):
super().clean()
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:
raise ValidationError({'location': 'Choose one of your own locations.'})
if self.user_id and self.category_id and self.category.user_id != self.user_id:
raise ValidationError({'category': 'Choose one of your own categories.'})