33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from sqlalchemy import Column, String, Integer, Float, Text, ForeignKey, Table
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.models.base import Base
|
|
|
|
# Association table for the many-to-many relationship between Product and Category
|
|
product_category = Table(
|
|
"product_category",
|
|
Base.metadata,
|
|
Column("product_id", Integer, ForeignKey("product.id"), primary_key=True),
|
|
Column("category_id", Integer, ForeignKey("category.id"), primary_key=True),
|
|
)
|
|
|
|
|
|
class Product(Base):
|
|
"""Model for anime merchandise products."""
|
|
|
|
name = Column(String(255), nullable=False, index=True)
|
|
description = Column(Text, nullable=True)
|
|
price = Column(Float, nullable=False)
|
|
stock = Column(Integer, default=0, nullable=False)
|
|
image_url = Column(String(255), nullable=True)
|
|
anime_title = Column(String(255), nullable=True, index=True)
|
|
character_name = Column(String(255), nullable=True, index=True)
|
|
|
|
# Relationships
|
|
categories = relationship(
|
|
"Category", secondary=product_category, back_populates="products"
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<Product {self.name}>"
|