refactor: P2 core+common 建设(应用工厂/扩展/工具层迁入 src/)
【结构】 - src/core/:database/response/jwt/password/security/redis_client/mail/scheduler - src/common/:base_model/base_db/forms(base_form+fields)/constants/utils - src/models_registry.py:模型聚合器(Flask-Migrate 全量表识别) 【绞杀者 shim】extensions/、utils/、application/constants|forms|models 打兼容转发 【兼容修复】应用工厂抽取至 application/factory.py(P2 前置,P1 已完成) 【基线修复】application/models(25) + middleware(7) 原被嵌套 .gitignore(*) 误排除出版本库,已补入(base_model/base_db 现为 shim,原版在 src/common/) 【登记既有缺陷】 1. flask db CLI 因 .env FLASK_VERSION 与 --version 冲突报错 → Makefile 已加 FLASK_SKIP_DOTENV=1 2. 本机 Redis 未设密码但 REDIS_AUTH=True,/captcha 报 AUTH 错误(环境问题) 【验收】22 模型表全量识别;src/ flake8 零告警;pytest 5 passed;应用启动; /login 表单校验、/user/page 鉴权拦截冒烟正常 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
92130ef070
commit
658ee6d596
@@ -0,0 +1,122 @@
|
||||
"""
|
||||
分类模型模块
|
||||
=============================================================
|
||||
|
||||
提供文章分类管理的数据模型定义,支持多级分类结构。
|
||||
"""
|
||||
|
||||
from application.models.base_db import BaseDB
|
||||
from application.models.base_model import BaseModel
|
||||
from config import DB_PREFIX
|
||||
from extensions import db
|
||||
from utils.case_converter import convert_camel_to_snake
|
||||
|
||||
|
||||
# ============================================================
|
||||
# 分类模型
|
||||
# ============================================================
|
||||
|
||||
class Category(BaseModel, BaseDB):
|
||||
"""
|
||||
分类模型
|
||||
|
||||
用于存储文章分类数据,支持多级分类结构(无限级)。
|
||||
继承自 BaseModel(通用字段)和 BaseDB(数据库操作方法)。
|
||||
|
||||
Attributes:
|
||||
id: 主键ID(继承自 BaseModel)
|
||||
category_name: 分类名称(String(100),必填)
|
||||
category_code: 分类编码(String(100),可选)
|
||||
parent_id: 上级分类ID(Integer,默认0,0表示顶级分类)
|
||||
sort: 分类排序(Integer,默认0,数值越小越靠前)
|
||||
note: 分类备注(String(100),可选)
|
||||
type: 分类类型(Integer,必填,1-公司,2-子公司,3-部门,4-小组)
|
||||
"""
|
||||
|
||||
# ============================================================
|
||||
# 表配置
|
||||
# ============================================================
|
||||
|
||||
# 设置表名
|
||||
__tablename__ = DB_PREFIX + "category"
|
||||
|
||||
# ============================================================
|
||||
# 字段定义
|
||||
# ============================================================
|
||||
|
||||
# 分类名称
|
||||
category_name = db.Column(
|
||||
db.String(100),
|
||||
nullable=False,
|
||||
comment="分类名称"
|
||||
)
|
||||
|
||||
# 分类编码
|
||||
category_code = db.Column(
|
||||
db.String(100),
|
||||
nullable=True,
|
||||
comment="分类编码"
|
||||
)
|
||||
|
||||
# 上级分类ID
|
||||
parent_id = db.Column(
|
||||
db.Integer,
|
||||
nullable=False,
|
||||
default=0,
|
||||
comment="上级ID"
|
||||
)
|
||||
|
||||
# 分类排序
|
||||
sort = db.Column(
|
||||
db.Integer,
|
||||
nullable=False,
|
||||
default=0,
|
||||
comment="排序"
|
||||
)
|
||||
|
||||
# 分类备注
|
||||
note = db.Column(
|
||||
db.String(100),
|
||||
nullable=True,
|
||||
comment="分类备注"
|
||||
)
|
||||
|
||||
# 分类类型
|
||||
type = db.Column(
|
||||
db.Integer,
|
||||
nullable=False,
|
||||
comment="分类类型:1-公司 2-子公司 3-部门 4-小组"
|
||||
)
|
||||
|
||||
# ============================================================
|
||||
# 常量定义
|
||||
# ============================================================
|
||||
|
||||
class Type:
|
||||
"""分类类型常量"""
|
||||
COMPANY = 1 # 公司
|
||||
SUBSIDIARY = 2 # 子公司
|
||||
DEPARTMENT = 3 # 部门
|
||||
GROUP = 4 # 小组
|
||||
|
||||
# ============================================================
|
||||
# 魔法方法
|
||||
# ============================================================
|
||||
|
||||
def __repr__(self):
|
||||
"""
|
||||
返回模型的字符串表示
|
||||
|
||||
Returns:
|
||||
str: 格式为 "分类:{category_name}" 的字符串
|
||||
"""
|
||||
return '分类:{}'.format(self.category_name)
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
返回模型的字符串表示
|
||||
|
||||
Returns:
|
||||
str: 格式为 "分类:{category_name}" 的字符串
|
||||
"""
|
||||
return self.__repr__()
|
||||
Reference in New Issue
Block a user