api/app/models/clothing.py
2025-04-09 21:45:42 +08:00

35 lines
1.5 KiB
Python

from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.db.database import Base
class ClothingCategory(Base):
"""衣服分类表"""
__tablename__ = "clothing_category"
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
name = Column(String(50), nullable=False, comment="分类名称")
create_time = Column(DateTime, default=func.now(), comment="创建时间")
# 关系
clothes = relationship("Clothing", back_populates="category", cascade="all, delete-orphan")
def __repr__(self):
return f"<ClothingCategory(id={self.id}, name={self.name})>"
class Clothing(Base):
"""衣服表"""
__tablename__ = "clothing"
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
clothing_category_id = Column(Integer, ForeignKey("clothing_category.id"), nullable=False, index=True, comment="分类ID")
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
image_url = Column(String(500), nullable=False, comment="图片URL")
create_time = Column(DateTime, default=func.now(), comment="创建时间")
# 关系
category = relationship("ClothingCategory", back_populates="clothes")
user = relationship("User", back_populates="clothings")
def __repr__(self):
return f"<Clothing(id={self.id}, category_id={self.clothing_category_id})>"