gabcares commited on
Commit
d87e376
·
verified ·
1 Parent(s): 02bb7cd

Update utils/student.py

Browse files
Files changed (1) hide show
  1. utils/student.py +37 -37
utils/student.py CHANGED
@@ -1,37 +1,37 @@
1
- from typing import Optional
2
- from pydantic import model_validator
3
- from sqlmodel import Field
4
- from typing_extensions import Self
5
-
6
- from .person import Person
7
- from utils.enums.major import Major
8
-
9
-
10
- class Student(Person, table=True):
11
- """
12
- Represents a Student, inheriting from Person, with an additional major field.
13
-
14
- Attributes:
15
- major (Major): The major that the student is pursuing.
16
-
17
- Methods:
18
- set_id() -> Self: An SQLModel model validator that automatically sets the student's ID with a "STU" prefix through handle_id method in the Person class.
19
- """
20
-
21
- major: Major = Field(sa_column=Field(sa_type=Major))
22
-
23
- @model_validator(mode='after')
24
- def set_id(self) -> Self:
25
- self.handle_id(prefix="STU")
26
-
27
- return self
28
-
29
- def __str__(self) -> str:
30
- """
31
- Returns a string representation of the student.
32
-
33
- Returns:
34
- str: A description of the student including their name, ID number, and major.
35
- """
36
-
37
- return f"Student(name: {self.name}, id: {self.id}, major: {self.major.value})"
 
1
+ from typing import Optional
2
+ from pydantic import model_validator
3
+ from sqlmodel import Field
4
+ from typing_extensions import Self
5
+
6
+ from .person import Person
7
+ from utils.enums.major import Major
8
+
9
+
10
+ class Student(Person, table=True):
11
+ """
12
+ Represents a Student, inheriting from Person, with an additional major field.
13
+
14
+ Attributes:
15
+ major (str): The major that the student is pursuing.
16
+
17
+ Methods:
18
+ set_id() -> Self: An SQLModel model validator that automatically sets the student's ID with a "STU" prefix through handle_id method in the Person class.
19
+ """
20
+
21
+ major: str = Field(default=Major.COMPUTER_SCIENCE)
22
+
23
+ @model_validator(mode='after')
24
+ def set_id(self) -> Self:
25
+ self.handle_id(prefix="STU")
26
+
27
+ return self
28
+
29
+ def __str__(self) -> str:
30
+ """
31
+ Returns a string representation of the student.
32
+
33
+ Returns:
34
+ str: A description of the student including their name, ID number, and major.
35
+ """
36
+
37
+ return f"Student(name: {self.name}, id: {self.id}, major: {self.major})"