34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from sqlalchemy import Boolean, Column, Float, ForeignKey, Integer, String, Text
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.db.session import Base
|
|
from app.models.base import Base as BaseModel
|
|
|
|
|
|
class Category(Base, BaseModel):
|
|
"""Category model."""
|
|
|
|
name = Column(String(100), nullable=False, unique=True)
|
|
description = Column(Text, nullable=True)
|
|
|
|
# Relationships
|
|
products = relationship("Product", back_populates="category")
|
|
|
|
|
|
class Product(Base, BaseModel):
|
|
"""Product model."""
|
|
|
|
name = Column(String(255), nullable=False, index=True)
|
|
description = Column(Text, nullable=True)
|
|
price = Column(Float, nullable=False)
|
|
stock_quantity = Column(Integer, nullable=False, default=0)
|
|
is_active = Column(Boolean, default=True)
|
|
image_url = Column(String(255), nullable=True)
|
|
|
|
# Foreign keys
|
|
category_id = Column(String(36), ForeignKey("category.id"), nullable=True)
|
|
|
|
# Relationships
|
|
category = relationship("Category", back_populates="products")
|
|
order_items = relationship("OrderItem", back_populates="product")
|
|
cart_items = relationship("CartItem", back_populates="product") |