summaryrefslogtreecommitdiff
path: root/kitchen/migrations/0003_pantryitem_state.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/migrations/0003_pantryitem_state.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/migrations/0003_pantryitem_state.py')
-rw-r--r--kitchen/migrations/0003_pantryitem_state.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/kitchen/migrations/0003_pantryitem_state.py b/kitchen/migrations/0003_pantryitem_state.py
new file mode 100644
index 0000000..a380a39
--- /dev/null
+++ b/kitchen/migrations/0003_pantryitem_state.py
@@ -0,0 +1,42 @@
+from django.db import migrations, models
+
+
+def backfill_state(apps, schema_editor):
+ """Items at quantity 0 are 'out'; everything else is 'in' (the field default)."""
+ PantryItem = apps.get_model("kitchen", "PantryItem")
+ PantryItem.objects.filter(quantity=0).update(state="out")
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("kitchen", "0002_add_rating_and_preferences"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="pantryitem",
+ name="state",
+ field=models.CharField(
+ choices=[("in", "In stock"), ("low", "Running low"), ("out", "Out")],
+ default="in",
+ max_length=10,
+ ),
+ ),
+ # Runs while quantity is still a Decimal column — 0 matches fine.
+ migrations.RunPython(backfill_state, migrations.RunPython.noop),
+ migrations.AlterField(
+ model_name="pantryitem",
+ name="quantity",
+ field=models.PositiveIntegerField(
+ blank=True,
+ help_text="Optional rough count; In/Low/Out is the primary signal",
+ null=True,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="pantryitem",
+ name="unit",
+ field=models.CharField(blank=True, max_length=20),
+ ),
+ ]