""" 品类相关模型 包含:品类、子类型、颜色 """ from sqlalchemy import Column, Integer, String, ForeignKey from sqlalchemy.orm import relationship from ..database import Base class Category(Base): """品类表""" __tablename__ = "categories" id = Column(Integer, primary_key=True, autoincrement=True, comment="品类ID") name = Column(String(50), nullable=False, comment="品类名称") icon = Column(String(255), nullable=True, comment="品类图标") sort_order = Column(Integer, default=0, comment="排序") flow_type = Column(String(20), nullable=False, comment="流程类型:full/size_color/simple") # 关联关系 sub_types = relationship("SubType", back_populates="category") colors = relationship("Color", back_populates="category") designs = relationship("Design", back_populates="category") def __repr__(self): return f"" class SubType(Base): """子类型表""" __tablename__ = "sub_types" id = Column(Integer, primary_key=True, autoincrement=True, comment="子类型ID") category_id = Column(Integer, ForeignKey("categories.id"), nullable=False, comment="所属品类") name = Column(String(50), nullable=False, comment="名称") description = Column(String(255), nullable=True, comment="描述") preview_image = Column(String(255), nullable=True, comment="预览图") sort_order = Column(Integer, default=0, comment="排序") # 关联关系 category = relationship("Category", back_populates="sub_types") designs = relationship("Design", back_populates="sub_type") def __repr__(self): return f"" class Color(Base): """颜色表""" __tablename__ = "colors" id = Column(Integer, primary_key=True, autoincrement=True, comment="颜色ID") category_id = Column(Integer, ForeignKey("categories.id"), nullable=False, comment="适用品类") name = Column(String(50), nullable=False, comment="颜色名称") hex_code = Column(String(7), nullable=False, comment="色值") sort_order = Column(Integer, default=0, comment="排序") # 关联关系 category = relationship("Category", back_populates="colors") designs = relationship("Design", back_populates="color") def __repr__(self): return f""