42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from sqlalchemy import Boolean, Index, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from src.db.base import Base
|
|
|
|
|
|
class OrgUnit(Base):
|
|
__tablename__ = "org_unit"
|
|
__table_args__ = (
|
|
Index(
|
|
"ix_v4_org_unit_active",
|
|
"is_active",
|
|
postgresql_where="is_active",
|
|
),
|
|
{"schema": "v3"},
|
|
)
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
title: Mapped[str] = mapped_column(String)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
|
is_ssp: Mapped[bool] = mapped_column(Boolean)
|
|
|
|
@property
|
|
def users_count(self) -> int | None:
|
|
return len(self.users) if self.users is not None else None
|
|
|
|
|
|
# budget_forms: Mapped[list["BudgetForm"]] = relationship( # type: ignore
|
|
# "BudgetForm", back_populates="org_unit"
|
|
# )
|
|
# audit_logs: Mapped[list["AuditLog"]] = relationship( # type: ignore
|
|
# "AuditLog", back_populates="org_unit"
|
|
# )
|
|
# projects: Mapped[list["Project"]] = relationship( # type: ignore
|
|
# "Project", back_populates="org_unit"
|
|
# )
|
|
vsps: Mapped[list["Vsp"]] = relationship("Vsp", back_populates="org_unit") # type: ignore
|
|
user_orgs: Mapped[list["UserOrg"]] = relationship("UserOrg", back_populates="org_unit")
|
|
users: Mapped[list["AppUser"]] = relationship("AppUser", secondary="v3.user_org", back_populates="org_units")
|