Files
FastapiAdmin/backend/app/api/v1/module_system/dept/model.py
T
zhangtao 700d76ad5a feat(model): 添加status字段表示启用状态
- 在myapp模块的ApplicationModel中新增status字段,标识应用是否启用
- 在demo模块的DemoModel中新增status字段,标识示例条目是否启用
- 修改代码生成模块相关模型,替换BaseMixin为CreatorMixin
- 删除代码生成模块中Python模板相关文件与Vue前端代码模板,优化代码结构和清理无用模板文件
2025-09-17 01:33:53 +08:00

30 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
from typing import Optional, List
from sqlalchemy import Boolean, String, Integer, ForeignKey
from sqlalchemy.orm import relationship, Mapped, mapped_column
from app.core.base_model import ModelMixin
class DeptModel(ModelMixin):
"""
部门表
"""
__tablename__ = "system_dept"
__table_args__ = ({'comment': '部门表'})
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True, comment='主键ID')
# 基础字段
name: Mapped[str] = mapped_column(String(40),nullable=False,unique=True,comment="部门名称")
order: Mapped[int] = mapped_column(Integer,nullable=False,default=999,comment="显示排序")
code: Mapped[Optional[str]] = mapped_column(String(20),nullable=True,unique=True,comment="部门编码")
status: Mapped[bool] = mapped_column(Boolean(), default=True, nullable=False, comment="是否启用(True:启用 False:禁用)")
parent_id: Mapped[Optional[int]] = mapped_column(Integer, ForeignKey("system_dept.id", ondelete="SET NULL", onupdate="CASCADE"), default=None, index=True, comment="父级部门ID")
parent: Mapped[Optional['DeptModel']] = relationship(back_populates='children', remote_side=[id],uselist=False)
children: Mapped[Optional[List['DeptModel']]] = relationship(back_populates='parent')
# 角色关联关系
roles: Mapped[List["RoleModel"]] = relationship(secondary="system_role_depts", back_populates="depts", lazy="selectin")
# 用户关联关系
users: Mapped[List["UserModel"]] = relationship(back_populates="dept", lazy="selectin")