-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
33 lines (24 loc) · 716 Bytes
/
schemas.py
File metadata and controls
33 lines (24 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from pydantic import BaseModel, validator, Field
from datetime import date
from typing import List
class Genre(BaseModel):
name: str
class Book(BaseModel):
title: str
writer: str
duration: str
date: date
summary: str
genres: List[Genre] = []
pages: int
class BookOut(Book):
id: int
class Author(BaseModel):
first_name: str = Field(..., max_length= 31)
last_name: str = Field(..., min_length= 3)
age: int = Field(..., gt=14, lt=90, description="Author shouldn`t be younger than 15 and older than 90")
# @validator('age')
# def check_age(cls, v):
# if v < 14 > 90:
# raise ValueError('Author age must be more than 14')
# return v