Fix seed: use ingredient+location for get_or_create, add missing freezer items
This commit is contained in:
@@ -95,12 +95,14 @@ class Command(BaseCommand):
|
|||||||
self.stdout.write("Creating pantry items...")
|
self.stdout.write("Creating pantry items...")
|
||||||
|
|
||||||
def add_pantry(name, qty, unit, location, expiry=None, is_staple=False, notes=""):
|
def add_pantry(name, qty, unit, location, expiry=None, is_staple=False, notes=""):
|
||||||
|
# Use ingredient + location for lookup so same ingredient can exist
|
||||||
|
# in multiple locations (e.g. sausages in fridge AND freezer)
|
||||||
PantryItem.objects.get_or_create(
|
PantryItem.objects.get_or_create(
|
||||||
ingredient=ingredients[name],
|
ingredient=ingredients[name],
|
||||||
|
location=location,
|
||||||
defaults={
|
defaults={
|
||||||
"quantity": Decimal(str(qty)),
|
"quantity": Decimal(str(qty)),
|
||||||
"unit": unit,
|
"unit": unit,
|
||||||
"location": location,
|
|
||||||
"expiry_date": expiry,
|
"expiry_date": expiry,
|
||||||
"is_staple": is_staple,
|
"is_staple": is_staple,
|
||||||
"notes": notes,
|
"notes": notes,
|
||||||
@@ -120,10 +122,10 @@ class Command(BaseCommand):
|
|||||||
add_pantry("Lao Gan Ma", 1, "jars", "cupboard")
|
add_pantry("Lao Gan Ma", 1, "jars", "cupboard")
|
||||||
add_pantry("sausages", 3, "items", "fridge", expiry=date(2026, 3, 30), notes="Likely expired — sniff test")
|
add_pantry("sausages", 3, "items", "fridge", expiry=date(2026, 3, 30), notes="Likely expired — sniff test")
|
||||||
|
|
||||||
# Freezer
|
# Freezer (same ingredient can exist in fridge AND freezer)
|
||||||
add_pantry("sausages", 3, "items", "freezer", notes="From frozen pack")
|
add_pantry("sausages", 3, "items", "freezer", notes="From frozen pack")
|
||||||
add_pantry("frozen chips", 1, "bags", "freezer", is_staple=True)
|
|
||||||
add_pantry("bread", 1, "loaves", "freezer", notes="Sliced")
|
add_pantry("bread", 1, "loaves", "freezer", notes="Sliced")
|
||||||
|
add_pantry("frozen chips", 1, "bags", "freezer", is_staple=True)
|
||||||
|
|
||||||
# Staples (seasonings — always in cupboard)
|
# Staples (seasonings — always in cupboard)
|
||||||
for name in ["salt", "black pepper", "olive oil", "paprika", "garlic powder"]:
|
for name in ["salt", "black pepper", "olive oil", "paprika", "garlic powder"]:
|
||||||
|
|||||||
Reference in New Issue
Block a user