Files
DjangoAdmin_Flask_EleVue/application/models/param.py
T
DjangoAdmin DevandClaude 658ee6d596 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>
2026-08-07 13:20:46 +08:00

118 lines
3.1 KiB
Python
Raw 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 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 Param(BaseModel, BaseDB):
"""
参数模型
用于存储系统参数和业务参数信息,如:系统配置参数、业务规则参数等。
继承自 BaseModel(通用字段)和 BaseDB(数据库操作方法)。
Attributes:
id: 主键ID(继承自 BaseModel)
name: 参数名称(String(100),必填)
code: 参数编码(String(100),必填,唯一标识)
value: 参数值(String(255),必填)
type: 参数类型(Integer,0-系统 1-业务,必填)
status: 参数状态(Integer,1-正常 2-禁用,必填)
sort: 参数排序(Integer,默认0,数值越小越靠前)
note: 参数备注(String(255),可选)
"""
# ============================================================
# 表配置
# ============================================================
# 设置表名
__tablename__ = DB_PREFIX + "param"
# ============================================================
# 字段定义
# ============================================================
# 参数名称
name = db.Column(
db.String(100),
nullable=False,
comment="参数名称"
)
# 参数编码
code = db.Column(
db.String(100),
nullable=False,
comment="参数编码"
)
# 参数值
value = db.Column(
db.String(255),
nullable=False,
comment="参数值"
)
# 参数类型:0-系统 1-业务
type = db.Column(
db.Integer,
nullable=False,
comment="参数类型:0-系统 1-业务"
)
# 参数状态:1-正常 2-禁用
status = db.Column(
db.Integer,
nullable=False,
comment="参数状态:1-正常 2-禁用"
)
# 参数排序
sort = db.Column(
db.Integer,
nullable=False,
comment="参数排序"
)
# 参数备注
note = db.Column(
db.String(255),
nullable=True,
comment="参数备注"
)
# ============================================================
# 魔法方法
# ============================================================
def __repr__(self):
"""
返回模型的字符串表示
Returns:
str: 格式为 "参数:{name}" 的字符串
"""
return '参数:{}'.format(self.name)
def __str__(self):
"""
返回模型的字符串表示
Returns:
str: 格式为 "参数:{name}" 的字符串
"""
return self.__repr__()