summaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorTyler Hoang <tyler@tylerhoang.xyz>2026-05-08 01:58:48 -0700
committerTyler Hoang <tyler@tylerhoang.xyz>2026-05-08 01:58:48 -0700
commit2e0a94e88c847a5ed8dc6ad5fa49715cd631bdfe (patch)
tree0c27fc5a8d8cbba60e571bb6690a13c0c0060ff4 /models.py
Initial commit — Commis personal chef app
AI-powered local chef tool: pantry tracking, meal logging, rotating weekly menu generation, and grocery list optimization via Ollama (llama3). FastAPI backend, SQLite, vanilla JS frontend. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'models.py')
-rw-r--r--models.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/models.py b/models.py
new file mode 100644
index 0000000..7594409
--- /dev/null
+++ b/models.py
@@ -0,0 +1,75 @@
+from datetime import datetime, date
+from sqlalchemy import Column, Integer, String, Float, DateTime, Date, Text, Boolean, ForeignKey
+from sqlalchemy.orm import relationship
+from database import Base
+
+
+class Ingredient(Base):
+ __tablename__ = "ingredients"
+
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ name = Column(String, nullable=False)
+ quantity = Column(Float, nullable=False)
+ unit = Column(String, nullable=False)
+ category = Column(String, nullable=True)
+ expiry_date = Column(Date, nullable=True)
+ added_at = Column(DateTime, default=datetime.utcnow)
+ updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
+
+
+class MealLog(Base):
+ __tablename__ = "meal_log"
+
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ meal_name = Column(String, nullable=False)
+ meal_type = Column(String, nullable=False)
+ eaten_at = Column(DateTime, nullable=False, default=datetime.utcnow)
+ notes = Column(String, nullable=True)
+ servings = Column(Integer, default=1)
+ ingredients = relationship("MealIngredient", cascade="all, delete-orphan")
+
+
+class MealIngredient(Base):
+ __tablename__ = "meal_ingredients"
+
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ meal_log_id = Column(Integer, ForeignKey("meal_log.id", ondelete="CASCADE"), nullable=False)
+ ingredient_name = Column(String, nullable=False)
+ quantity_used = Column(Float, nullable=True)
+ unit = Column(String, nullable=True)
+
+
+class Recipe(Base):
+ __tablename__ = "recipes"
+
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ name = Column(String, nullable=False)
+ meal_type = Column(String, nullable=False)
+ ingredients = Column(Text, nullable=False)
+ instructions = Column(Text, nullable=True)
+ estimated_time_minutes = Column(Integer, nullable=True)
+ servings = Column(Integer, default=2)
+ source = Column(String, default="ai")
+ created_at = Column(DateTime, default=datetime.utcnow)
+
+
+class MenuPlan(Base):
+ __tablename__ = "menu_plans"
+
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ week_start = Column(Date, nullable=False, unique=True)
+ plan = Column(Text, nullable=False)
+ generated_at = Column(DateTime, default=datetime.utcnow)
+ model_used = Column(String, nullable=True)
+
+
+class GroceryList(Base):
+ __tablename__ = "grocery_lists"
+
+ id = Column(Integer, primary_key=True, autoincrement=True)
+ generated_for = Column(Date, nullable=False)
+ items = Column(Text, nullable=False)
+ total_estimate = Column(Float, nullable=True)
+ generated_at = Column(DateTime, default=datetime.utcnow)
+ is_purchased = Column(Boolean, default=False)
+ notes = Column(Text, nullable=True)