34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
from sqlalchemy import Column, Integer, String, Float, DateTime, Boolean, Text, ForeignKey, JSON, DECIMAL
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
from app.database.database import Base
|
|
|
|
|
|
class Product(Base):
|
|
__tablename__ = "product"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, index=True)
|
|
slug = Column(String, unique=True, index=True, nullable=True)
|
|
description = Column(Text)
|
|
price = Column(Float)
|
|
discount_price = Column(Float, nullable=True)
|
|
category_id = Column(Integer, ForeignKey("category.id"))
|
|
model_id = Column(Integer, ForeignKey("model.id", ondelete="SET NULL"), nullable=True)
|
|
gender = Column(String) # men, women
|
|
brand = Column(String)
|
|
sizes = Column(JSON) # ["S", "M", "L", "XL", ...]
|
|
colors = Column(JSON) # ["Red", "Blue", ...]
|
|
stock = Column(Integer, nullable=True, default=None)
|
|
images = Column(JSON) # Array of image URLs
|
|
is_featured = Column(Boolean, default=False)
|
|
is_on_sale = Column(Boolean, default=False)
|
|
override_price = Column(DECIMAL(10, 2), nullable=True)
|
|
override_sizes = Column(JSON, nullable=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
category = relationship("Category")
|
|
model = relationship("Model", back_populates="products")
|
|
cart_items = relationship("CartItem", back_populates="product")
|
|
order_items = relationship("OrderItem", back_populates="product")
|