48 lines
1006 B
Python
48 lines
1006 B
Python
from typing import Optional
|
|
from pydantic import BaseModel
|
|
|
|
# Import at the top to avoid circular imports
|
|
from app.schemas.teacher import Teacher
|
|
|
|
|
|
# Shared properties
|
|
class CourseBase(BaseModel):
|
|
course_code: str
|
|
title: str
|
|
description: Optional[str] = None
|
|
credits: Optional[int] = None
|
|
is_active: bool = True
|
|
teacher_id: Optional[int] = None
|
|
|
|
|
|
# Properties to receive via API on creation
|
|
class CourseCreate(CourseBase):
|
|
course_code: str
|
|
title: str
|
|
|
|
|
|
# Properties to receive via API on update
|
|
class CourseUpdate(CourseBase):
|
|
course_code: Optional[str] = None
|
|
title: Optional[str] = None
|
|
teacher_id: Optional[int] = None
|
|
|
|
|
|
class CourseInDBBase(CourseBase):
|
|
id: int
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
# Additional properties to return via API
|
|
class Course(CourseInDBBase):
|
|
pass
|
|
|
|
|
|
# Course with Teacher details
|
|
class CourseWithTeacher(Course):
|
|
teacher: Optional[Teacher] = None
|
|
|
|
# Update forward refs
|
|
CourseWithTeacher.model_rebuild() |