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>
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
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),
|
|
),
|
|
]
|