refactor: P3a 模型层迁入 src/modules/(22 模型)
- 19 个模块目录(system/association/cms/dictionary/configuration/log 等) - 一对一 16 个 + 合并 3 组(dict+dict_item、config+config_item、login_log+operation_log) - 重写模型 import:base_db/base_model→src.common、db→src.core.database、 case_converter/rich_text/request→src.common.utils - application/models/ 全部替换为 shim(指向 src.modules) - src/models_registry.py 改为从 src.modules 全量导入 【修复】codemod 两处 bug:shim 与 registry 的 import 路径含斜杠(已改点分); strip_license 误剥无许可头文件的 docstring 开头(log/models.py 已补回) 【验收】22 表全量识别;应用启动;pytest 5 passed Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude
parent
658ee6d596
commit
6de4f3bef2
@@ -1,122 +1,8 @@
|
||||
"""
|
||||
分类模型模块
|
||||
兼容 shim(绞杀者迁移期间保留)
|
||||
=============================================================
|
||||
|
||||
提供文章分类管理的数据模型定义,支持多级分类结构。
|
||||
模型已迁移至 src.modules.cms.category.models。
|
||||
本文件仅作兼容转发,最终在 P7(切尾)阶段删除。
|
||||
"""
|
||||
|
||||
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__()
|
||||
from src.modules.cms.category.models import * # noqa: F401,F403
|
||||
|
||||
Reference in New Issue
Block a user