47 lines
1009 B
Python

from typing import Optional
from datetime import date
from pydantic import BaseModel
# Import at the top to avoid circular imports
from app.schemas.user import User as UserOut
# Shared properties
class StudentBase(BaseModel):
student_id: Optional[str] = None
date_of_birth: Optional[date] = None
address: Optional[str] = None
phone_number: Optional[str] = None
grade_level: Optional[str] = None
user_id: Optional[int] = None
# Properties to receive via API on creation
class StudentCreate(StudentBase):
student_id: str
user_id: int
# Properties to receive via API on update
class StudentUpdate(StudentBase):
pass
class StudentInDBBase(StudentBase):
id: Optional[int] = None
class Config:
from_attributes = True
# Additional properties to return via API
class Student(StudentInDBBase):
pass
# Student with User details
class StudentWithUser(Student):
user: Optional[UserOut] = None
# Update forward refs
StudentWithUser.model_rebuild()