26 lines
754 B
Python
26 lines
754 B
Python
from pydantic import BaseModel, Field
|
|
|
|
class CountryBase(BaseModel):
|
|
name: str = Field(..., index=True, unique=True, description="Country name")
|
|
code: str = Field(..., min_length=3, max_length=3, description="Country code (3 characters)")
|
|
population: int = Field(..., gt=0, description="Country population")
|
|
area: int = Field(..., gt=0, description="Country area")
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "United States",
|
|
"code": "USA",
|
|
"population": 329500000,
|
|
"area": 9833520
|
|
}
|
|
}
|
|
|
|
class CountryCreate(CountryBase):
|
|
pass
|
|
|
|
class CountryResponse(CountryBase):
|
|
id: int
|
|
|
|
class Config:
|
|
orm_mode = True |