2025-03-28 15:59:12 +00:00

29 lines
1.1 KiB
Python

from sqlalchemy import Column, String, Integer, ForeignKey, Float, DateTime
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.sql import func
from core.database import Base
import uuid
class FoodCategory(Base):
__tablename__ = "food_categories"
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = Column(String, nullable=False, unique=True)
created_at = Column(DateTime, default=func.now())
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
foods = relationship("Food", back_populates="category")
class Food(Base):
__tablename__ = "foods"
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = Column(String, nullable=False)
description = Column(String, nullable=True)
price = Column(Float, nullable=False)
category_id = Column(UUID, ForeignKey("food_categories.id"), nullable=False)
created_at = Column(DateTime, default=func.now())
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
category = relationship("FoodCategory", back_populates="foods")