Files
FastapiAdmin/backend/app/api/v1/module_system/tenant/model.py
T
zhangtao 086bce3972 feat(tenant): 添加租户编码字段及相关功能
- 在后端模型、schema和前端接口中添加code字段
- 在前端表格和表单中显示和编辑code字段
- 修改租户名称长度限制从50到64字符
- 添加编码字段的验证逻辑
- 更新WangEditor组件返回纯文本格式
2025-11-13 23:47:52 +08:00

37 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
from typing import Optional, List, TYPE_CHECKING
from sqlalchemy import Boolean, String
from sqlalchemy.orm import Mapped, mapped_column, validates, relationship
from app.core.base_model import ModelMixin
class TenantModel(ModelMixin):
"""
租户表
"""
__tablename__ = 'system_tenant'
__table_args__ = ({'comment': '租户表'})
name: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, default='', comment='租户名称')
code: Mapped[Optional[str]] = mapped_column(String(20), nullable=True, default='', comment='租户编码')
status: Mapped[bool] = mapped_column(Boolean(), default=True, nullable=False, comment="是否启用(True:启用 False:禁用)")
@validates('name')
def validate_name(self, key: str, name: str) -> str:
"""验证名称不为空"""
if not name or not name.strip():
raise ValueError('名称不能为空')
return name
@validates('code')
def validate_code(self, key: str, code: str) -> str:
"""验证编码格式校验"""
if not code or not code.strip():
raise ValueError('编码不能为空')
if not code.isalnum():
raise ValueError('编码只能包含字母和数字')
return code