49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
"""老师表(需求 2.5)。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
from sqlalchemy import Date, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.model.assoc import class_teachers
|
|
from app.model.base import Base, SoftDeleteMixin, TimestampMixin
|
|
from app.model.constants import GENDER_TEXT
|
|
|
|
|
|
class Teacher(Base, TimestampMixin, SoftDeleteMixin):
|
|
__tablename__ = "teacher"
|
|
__table_args__ = {"comment": "授课老师表"}
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
teacher_no: Mapped[str] = mapped_column(String(20), unique=True, nullable=False, comment="工号")
|
|
name: Mapped[str] = mapped_column(String(30), nullable=False, index=True, comment="姓名")
|
|
gender: Mapped[int] = mapped_column(default=1, nullable=False, comment="性别 1=男 2=女")
|
|
phone: Mapped[str | None] = mapped_column(String(20), comment="手机号")
|
|
email: Mapped[str | None] = mapped_column(String(60), comment="邮箱")
|
|
title: Mapped[str | None] = mapped_column(String(30), comment="职称,如 讲师/高级讲师")
|
|
subject: Mapped[str | None] = mapped_column(String(50), comment="授课方向,如 Java/前端/大数据")
|
|
hire_date: Mapped[date | None] = mapped_column(Date, comment="入职时间")
|
|
remark: Mapped[str | None] = mapped_column(String(255), comment="备注")
|
|
|
|
# 带班信息:多对多
|
|
classes: Mapped[list["Clazz"]] = relationship( # noqa: F821
|
|
secondary=class_teachers,
|
|
back_populates="teachers",
|
|
lazy="selectin",
|
|
)
|
|
|
|
# ---------------- 出参派生字段 ----------------
|
|
@property
|
|
def gender_text(self) -> str | None:
|
|
return GENDER_TEXT.get(self.gender)
|
|
|
|
@property
|
|
def class_names(self) -> list[str]:
|
|
return [c.name for c in self.classes if c.is_del == 0]
|
|
|
|
@property
|
|
def class_count(self) -> int:
|
|
return len(self.class_names)
|