Add Meal model
This commit is contained in:
parent
4d20babd38
commit
0156ae51ca
29
models/meal.py
Normal file
29
models/meal.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from sqlalchemy import Column, String, Integer, Float, DateTime, ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
|
from core.database import Base
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
class Meal(Base):
|
||||||
|
__tablename__ = "meals"
|
||||||
|
|
||||||
|
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(as_uuid=True), ForeignKey('categories.id'), nullable=False)
|
||||||
|
created_at = Column(DateTime, default=func.now())
|
||||||
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
||||||
|
|
||||||
|
category = relationship("Category", back_populates="meals")
|
||||||
|
|
||||||
|
class Category(Base):
|
||||||
|
__tablename__ = "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())
|
||||||
|
|
||||||
|
meals = relationship("Meal", back_populates="category")
|
Loading…
x
Reference in New Issue
Block a user