Files
YuShiSheJiShi/backend/app/models/category.py
changyoutongxue e3ff55b4db docs(readme): 编写项目README文档,描述功能与架构
- 完整撰写玉宗珠宝设计大师项目README,介绍项目概况及核心功能
- 说明用户认证系统实现及优势,包含JWT鉴权和密码加密细节
- 详细描述品类管理系统,支持多流程类型和多种玉石品类
- 说明设计图生成方案及技术,包含Pillow生成示例及字体支持
- 介绍设计管理功能,支持分页浏览、预览、下载和删除设计
- 个人信息管理模块说明,涵盖昵称、手机号、密码的安全修改
- 绘制业务流程图和关键数据流图,清晰展现系统架构与数据流
- 提供详细API调用链路及参数说明,涵盖用户、品类、设计接口
- 列明技术栈及版本,包含前后端框架、ORM、认证、加密等工具
- 展示目录结构,标明后端与前端项目布局
- 规划本地开发环境与启动步骤,包括数据库初始化及运行命令
- 说明服务器部署流程和Nginx配置方案
- 详细数据库表结构说明及环境变量配置指导
- 汇总常用开发及测试命令,方便开发调试与部署管理
2026-03-27 13:10:17 +08:00

65 lines
2.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
品类相关模型
包含:品类、子类型、颜色
"""
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"<Category(id={self.id}, name='{self.name}')>"
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"<SubType(id={self.id}, name='{self.name}')>"
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"<Color(id={self.id}, name='{self.name}', hex_code='{self.hex_code}')>"