Files
loom/backend/app/models/organization.py
T
2026-04-24 17:46:03 +08:00

27 lines
1.1 KiB
Python

"""组织架构:公司 / 部门 / 小组 三级树。"""
from __future__ import annotations
from sqlalchemy import ForeignKey, Integer, String
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.db.base import Base, TimestampMixin
class Organization(Base, TimestampMixin):
__tablename__ = "organization"
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
parent_id: Mapped[int | None] = mapped_column(
ForeignKey("organization.id", ondelete="SET NULL"), nullable=True, index=True
)
name: Mapped[str] = mapped_column(String(64), nullable=False)
code: Mapped[str] = mapped_column(String(64), nullable=False, unique=True)
# company | department | group
type: Mapped[str] = mapped_column(String(16), nullable=False, default="department")
sort: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
description: Mapped[str | None] = mapped_column(String(255), nullable=True)
parent: Mapped["Organization | None"] = relationship(
"Organization", remote_side="Organization.id", backref="children"
)