31 lines
1.0 KiB
Python

from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
import uuid
# Base schema for Car, used for inheritance
class CarBase(BaseModel):
make: str = Field(..., description="Car make")
model: str = Field(..., description="Car model")
year: int = Field(..., description="Car year")
is_german: bool = Field(True, description="Whether the car is German or not")
# Schema for creating a new Car
class CarCreate(CarBase):
pass
# Schema for updating an existing Car (all fields optional)
class CarUpdate(CarBase):
make: Optional[str] = Field(None, description="Car make")
model: Optional[str] = Field(None, description="Car model")
year: Optional[int] = Field(None, description="Car year")
is_german: Optional[bool] = Field(None, description="Whether the car is German or not")
# Schema for representing a Car in responses
class CarSchema(CarBase):
id: uuid.UUID
created_at: datetime
updated_at: datetime
class Config:
orm_mode = True