Files
FastapiAdmin/backend/app/api/v1/module_system/dept/model.py
T
zhangtao e159b31e62 feat: Add role code to system_role.json and update system_users.json creator_id to null
fix: Refactor initialize.py to handle nested children data during initialization

feat: Implement tree structure traversal functions in common_util.py

chore: Update requirements.txt to specify sqlalchemy-crud-plus version and add rich

refactor: Change API endpoints in dept.ts and menu.ts to return tree structure

feat: Add code field to role, dept, and menu interfaces in respective TypeScript files

fix: Update dept and role Vue components to display and handle code field

docs: Add comprehensive project documentation for FastAPI Vue3 Admin
2025-09-15 00:19:11 +08:00

29 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
from typing import Optional, List
from sqlalchemy import 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="部门编码")
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")