Spaces:
Sleeping
Sleeping
| from sqlalchemy import Column, Integer, String, DateTime, text | |
| from sqlalchemy.orm import relationship | |
| from database import Base | |
| class Category(Base): | |
| __tablename__ = "categories" | |
| id = Column(Integer, primary_key=True, index=True, comment='主键 ID') | |
| parent_code = Column(String(100), nullable=False, server_default="", index=True, comment='父分类编码,空为顶级分类') | |
| code = Column(String(100), nullable=False, server_default="", index=True, comment='分类编码,级联编码格式') | |
| name = Column(String(100), nullable=False, server_default="", index=True, comment='分类名称') | |
| sort_order = Column(Integer, nullable=False, server_default="0", comment='排序顺序') | |
| status = Column(Integer, nullable=False, server_default="1", comment='状态:0-禁用,1-启用') | |
| company_code = Column(String(50), nullable=False, server_default="", index=True, comment='公司编码,用于数据隔离') | |
| created_at = Column(DateTime(timezone=True), nullable=False, server_default=text('CURRENT_TIMESTAMP'), comment='创建时间') | |
| updated_at = Column(DateTime(timezone=True), nullable=False, server_default=text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), comment='更新时间') | |
| # 关系 | |
| products = relationship("Product", back_populates="category") | |