summaryrefslogtreecommitdiff
path: root/kitchen/models.py
diff options
context:
space:
mode:
authorTom Flux <tom@tomflux.xyz>2026-06-23 19:55:16 +0100
committerTom Flux <tom@tomflux.xyz>2026-06-23 19:55:16 +0100
commit0aabf50834a31ff4ae9f8fd58639e444a449110b (patch)
tree3c0033c8326268e098ebf4bac020d5a427ee3f9c /kitchen/models.py
parente34081ce36d1993912dad514127924440437a2e9 (diff)
Phase 1: mobile-first pantry redesign with In/Low/Out state
Track presence (In/Low/Out) as the primary signal instead of exact quantities; quantity becomes an optional integer, unit optional too (migration 0003 backfills state from quantity: 0 -> out, else in). - Pantry rebuilt as a phone-first card list: colored state rail, segmented In/Low/Out switch (server-driven HTMX), greyed out-items, live summary counts. - Fast add: bottom add bar with type-ahead autocomplete, location picker, and quick-add chips for things you've run out of. - Per-item menu (move / set expiry / delete); expiry is now an optional quiet pill, never required. - New endpoints: pantry search + set-state; dropped the old edit-expiry/cancel flow and its partial. - Recipes matcher made presence-based (have-it beats have-enough); state added to admin. Tests cover state, add/restock, search, presence matching, and page rendering. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'kitchen/models.py')
-rw-r--r--kitchen/models.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/kitchen/models.py b/kitchen/models.py
index ab0a720..07bf231 100644
--- a/kitchen/models.py
+++ b/kitchen/models.py
@@ -50,9 +50,18 @@ class PantryItem(models.Model):
FREEZER = "freezer", "Freezer"
CUPBOARD = "cupboard", "Cupboard"
+ class State(models.TextChoices):
+ IN = "in", "In stock"
+ LOW = "low", "Running low"
+ OUT = "out", "Out"
+
ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE)
- quantity = models.DecimalField(max_digits=8, decimal_places=2)
- unit = models.CharField(max_length=20)
+ # In/Low/Out is the primary signal. quantity is an optional rough count.
+ state = models.CharField(max_length=10, choices=State.choices, default=State.IN)
+ quantity = models.PositiveIntegerField(
+ null=True, blank=True, help_text="Optional rough count; In/Low/Out is the primary signal"
+ )
+ unit = models.CharField(max_length=20, blank=True)
location = models.CharField(max_length=20, choices=Location.choices)
stored_date = models.DateField(auto_now_add=True)
expiry_date = models.DateField(null=True, blank=True)
@@ -65,7 +74,8 @@ class PantryItem(models.Model):
ordering = ["expiry_date", "ingredient__name"]
def __str__(self):
- return f"{self.ingredient.name} ({self.quantity} {self.unit}) [{self.location}]"
+ qty = f"{self.quantity} {self.unit}" if self.quantity is not None else self.get_state_display()
+ return f"{self.ingredient.name} ({qty}) [{self.location}]"
def clean(self):
"""Business rules for pantry items."""