We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 247e2c6 commit b29273dCopy full SHA for b29273d
1 file changed
ch04/todos/model.py
@@ -0,0 +1,53 @@
1
+from typing import List, Optional
2
+
3
+from fastapi import Form
4
+from pydantic import BaseModel
5
6
7
+class Todo(BaseModel):
8
+ id: Optional[int]
9
+ item: str
10
11
+ @classmethod
12
+ def as_form(
13
+ cls,
14
+ item: str = Form(...)
15
+ ):
16
+ return cls(item=item)
17
18
+ class Config:
19
+ schema_extra = {
20
+ "example": {
21
+ "id": 1,
22
+ "item": "Example schema!"
23
+ }
24
25
26
27
+class TodoItem(BaseModel):
28
29
30
31
32
33
+ "item": "Read the next chapter of the book"
34
35
36
37
38
+class TodoItems(BaseModel):
39
+ todos: List[TodoItem]
40
41
42
43
44
+ "todos": [
45
+ {
46
+ "item": "Example schema 1!"
47
+ },
48
49
+ "item": "Example schema 2!"
50
51
+ ]
52
53
0 commit comments