File size: 1,144 Bytes
4ee0abb
2333542
4ee0abb
 
2333542
4ee0abb
 
 
 
 
2333542
 
 
 
 
 
4ee0abb
 
 
 
 
2333542
 
 
 
4ee0abb
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# models.py
from sqlalchemy import Column, ForeignKey, Integer, String, Float, DateTime
from sqlalchemy.orm import relationship
from core.database import Base
from datetime import datetime

class Meal(Base):
    __tablename__ = "meals"

    id = Column(Integer, primary_key=True, index=True)
    name = Column(String, unique=True, nullable=False, index=True)
    description = Column(String, nullable=False)
    price = Column(Float, nullable=False)
    category = Column(String, nullable=True)  # Optional: To classify meals
    
    orders = relationship("Order", back_populates="meal", cascade="all, delete-orphan")

class Order(Base):
    __tablename__ = "orders"

    id = Column(Integer, primary_key=True, index=True)
    user_id = Column(Integer, ForeignKey("users.id"), nullable=False, index=True)
    meal_id = Column(Integer, ForeignKey("meals.id"), nullable=False, index=True)
    quantity = Column(Integer, nullable=False)
    timestamp = Column(DateTime, default=datetime.utcnow)  # To track when the order was made

    user = relationship("User", back_populates="orders")
    meal = relationship("Meal", back_populates="orders")