Spaces:
Sleeping
Sleeping
Update utils/instructor.py
Browse files- Use (department: Union[str, Department]
- Set default: default=Department.COMPUTER_SCIENCE
- utils/instructor.py +41 -41
utils/instructor.py
CHANGED
|
@@ -1,41 +1,41 @@
|
|
| 1 |
-
from typing_extensions import Self, Optional
|
| 2 |
-
from pydantic import model_validator
|
| 3 |
-
from sqlmodel import Field, Relationship
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
from .person import Person
|
| 7 |
-
from utils.enums.department import Department
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
class Instructor(Person, table=True):
|
| 11 |
-
"""
|
| 12 |
-
Represents an Instructor, inheriting from Person, with an additional department field.
|
| 13 |
-
|
| 14 |
-
Attributes:
|
| 15 |
-
department (Department): The instructor's department.
|
| 16 |
-
|
| 17 |
-
Methods:
|
| 18 |
-
set_id() -> Self: An SQLmodel validator that automatically sets the instructor's ID with a "INS" prefix through handle_id method in the Person class.
|
| 19 |
-
"""
|
| 20 |
-
|
| 21 |
-
department: Department = Field(
|
| 22 |
-
|
| 23 |
-
course_id: Optional[str] = Field(
|
| 24 |
-
default=None, foreign_key="course.id")
|
| 25 |
-
course: Optional["Course"] = Relationship(
|
| 26 |
-
back_populates="instructors")
|
| 27 |
-
|
| 28 |
-
@model_validator(mode='after')
|
| 29 |
-
def set_id(self) -> Self:
|
| 30 |
-
self.handle_id(prefix="INS")
|
| 31 |
-
return self
|
| 32 |
-
|
| 33 |
-
def __str__(self) -> str:
|
| 34 |
-
"""
|
| 35 |
-
Returns a string representation of the instructor.
|
| 36 |
-
|
| 37 |
-
Returns:
|
| 38 |
-
str: A description of the instructor including their name, ID number, and department.
|
| 39 |
-
"""
|
| 40 |
-
|
| 41 |
-
return f"Instructor(name: {self.name}, id: {self.id}, department: {self.department.value})"
|
|
|
|
| 1 |
+
from typing_extensions import Self, Optional
|
| 2 |
+
from pydantic import model_validator
|
| 3 |
+
from sqlmodel import Field, Relationship
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
from .person import Person
|
| 7 |
+
from utils.enums.department import Department
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Instructor(Person, table=True):
|
| 11 |
+
"""
|
| 12 |
+
Represents an Instructor, inheriting from Person, with an additional department field.
|
| 13 |
+
|
| 14 |
+
Attributes:
|
| 15 |
+
department (Union[str, Department): The instructor's department.
|
| 16 |
+
|
| 17 |
+
Methods:
|
| 18 |
+
set_id() -> Self: An SQLmodel validator that automatically sets the instructor's ID with a "INS" prefix through handle_id method in the Person class.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
department: Union[str, Department] = Field(default=Department.COMPUTER_SCIENCE)
|
| 22 |
+
|
| 23 |
+
course_id: Optional[str] = Field(
|
| 24 |
+
default=None, foreign_key="course.id")
|
| 25 |
+
course: Optional["Course"] = Relationship(
|
| 26 |
+
back_populates="instructors")
|
| 27 |
+
|
| 28 |
+
@model_validator(mode='after')
|
| 29 |
+
def set_id(self) -> Self:
|
| 30 |
+
self.handle_id(prefix="INS")
|
| 31 |
+
return self
|
| 32 |
+
|
| 33 |
+
def __str__(self) -> str:
|
| 34 |
+
"""
|
| 35 |
+
Returns a string representation of the instructor.
|
| 36 |
+
|
| 37 |
+
Returns:
|
| 38 |
+
str: A description of the instructor including their name, ID number, and department.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
return f"Instructor(name: {self.name}, id: {self.id}, department: {self.department.value})"
|