inf04-web2/app/schemas.py

30 lines
576 B
Python
Raw Permalink Normal View History

2024-06-20 19:10:59 +00:00
from typing import List, Optional
from pydantic import BaseModel, constr, conint
class AuthorCreate(BaseModel):
name: constr(min_length=2, max_length=100)
class AuthorModel(BaseModel):
id: int
name: str
class Config:
orm_mode = True
class BookCreate(BaseModel):
title: constr(min_length=1, max_length=100)
author_id: conint(gt=0)
class BookModel(BaseModel):
id: int
title: str
author_id: int
status: Optional[str] = None
class Config:
orm_mode = True
class BookWithAuthor(BookModel):
author: AuthorModel