Spaces:
Sleeping
Sleeping
| import uuid | |
| from datetime import date | |
| from sqlalchemy import String, ForeignKey, Date, Index | |
| from sqlalchemy.orm import Mapped, mapped_column, relationship | |
| from app.db.database import Base | |
| from app.models.base import AuditMixin | |
| from app.constants import BATCH_STATUS_ACTIVE | |
| from app.models.student_batch import student_batch_table | |
| class Batch(AuditMixin, Base): | |
| __tablename__ = "batches" | |
| __table_args__ = ( | |
| Index("ix_batch_mentor_deleted", "mentor_id", "deleted_at"), | |
| Index("ix_batch_status_deleted", "status", "deleted_at"), | |
| ) | |
| id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4())) | |
| name: Mapped[str] = mapped_column(String(200), nullable=False) | |
| course_id: Mapped[str] = mapped_column(String(36), ForeignKey("courses.id"), nullable=False) | |
| mentor_id: Mapped[str] = mapped_column(String(36), ForeignKey("mentors.id"), nullable=False) | |
| start_date: Mapped[date] = mapped_column(Date, nullable=False) | |
| # "Active" or "Completed" | |
| status: Mapped[str] = mapped_column(String(20), nullable=False, default=BATCH_STATUS_ACTIVE) | |
| course: Mapped["Course"] = relationship("Course", back_populates="batches") # noqa: F821 | |
| mentor: Mapped["Mentor"] = relationship("Mentor", back_populates="batches") # noqa: F821 | |
| students: Mapped[list["Student"]] = relationship( # noqa: F821 | |
| "Student", secondary=student_batch_table, back_populates="batches" | |
| ) | |
| sessions: Mapped[list["Session"]] = relationship( # noqa: F821 | |
| "Session", back_populates="batch", cascade="all, delete-orphan" | |
| ) | |