@@ -44,185 +44,29 @@ It's because we declared the `HeroPublic` with only the same base fields of the
4444
4545And the same way, we declared the ` TeamPublic ` with only the same base fields of the ` TeamBase ` plus the ` id ` . But it doesn't include a field ` heroes ` for the ** relationship attribute** .
4646
47- //// tab | Python 3.10+
47+ { * ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln [ 5:7 ] hl [ 3:5,9:10,23-24 ] * }
4848
49- ``` Python hl_lines="3-5 9-10 14-19 23-24"
50- # Code above omitted 👆
49+ {* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[ 20:21] hl[ 3:5,9:10,23-24] * }
5150
52- {! ./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py310.py[ln:5 - 7 ]! }
51+ {* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py[ ln:29-34 ] hl [ 3:5,9:10,23-24 ] * }
5352
54- # Code here omitted 👈
55-
56- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py310.py[ln:20 - 21 ]!}
57-
58- # Code here omitted 👈
59-
60- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py310.py[ln:29 - 34 ]!}
61-
62- # Code here omitted 👈
63-
64- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py310.py[ln:43 - 44 ]!}
65-
66- # Code below omitted 👇
67- ```
68-
69- ////
70-
71- //// tab | Python 3.9+
72-
73- ``` Python hl_lines="3-5 9-10 14-19 23-24"
74- # Code above omitted 👆
75-
76- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py39.py[ln:7 - 9 ]!}
77-
78- # Code here omitted 👈
79-
80- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py39.py[ln:22 - 23 ]!}
81-
82- # Code here omitted 👈
83-
84- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py39.py[ln:31 - 36 ]!}
85-
86- # Code here omitted 👈
87-
88- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py39.py[ln:45 - 46 ]!}
89-
90- # Code below omitted 👇
91- ```
92-
93- ////
94-
95- //// tab | Python 3.7+
96-
97- ``` Python hl_lines="3-5 9-10 14-19 23-24"
98- # Code above omitted 👆
99-
100- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001.py[ln:7 - 9 ]!}
101-
102- # Code here omitted 👈
103-
104- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001.py[ln:22 - 23 ]!}
105-
106- # Code here omitted 👈
107-
108- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001.py[ln:31 - 36 ]!}
109-
110- # Code here omitted 👈
111-
112- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001.py[ln:45 - 46 ]!}
113-
114- # Code below omitted 👇
115- ```
116-
117- ////
53+ {* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py[ ln:43-44] hl[ 3:5,9:10,23-24] * }
11854
11955/// details | 👀 Full file preview
12056
121- //// tab | Python 3.10+
122-
123- ``` Python
124- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py310.py!}
125- ```
126-
127- ////
128-
129- //// tab | Python 3.9+
130-
131- ``` Python
132- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py39.py!}
133- ```
134-
135- ////
136-
137- //// tab | Python 3.7+
138-
139- ``` Python
140- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001.py!}
141- ```
142-
143- ////
144-
145- ///
57+ {* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py * }
14658
14759Now, remember that <a href =" https://fastapi.tiangolo.com/tutorial/response-model/ " class =" external-link " target =" _blank " >FastAPI uses the ` response_model ` to validate and ** filter** the response data</a >?
14860
14961In this case, we used ` response_model=TeamPublic ` and ` response_model=HeroPublic ` , so FastAPI will use them to filter the response data, even if we return a ** table model** that includes ** relationship attributes** :
15062
151- //// tab | Python 3.10+
152-
153- ``` Python hl_lines="3 8 12 17"
154- # Code above omitted 👆
155-
156- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py310.py[ln:102 - 107 ]!}
157-
158- # Code here omitted 👈
159-
160- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py310.py[ln:156 - 161 ]!}
161-
162- # Code below omitted 👇
163- ```
164-
165- ////
166-
167- //// tab | Python 3.9+
168-
169- ``` Python hl_lines="3 8 12 17"
170- # Code above omitted 👆
63+ {* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[ 102:107] hl=[ 3,8,12,17] * }
17164
172- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py39.py[ln:104 - 109 ]!}
173-
174- # Code here omitted 👈
175-
176- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py39.py[ln:158 - 163 ]!}
177-
178- # Code below omitted 👇
179- ```
180-
181- ////
182-
183- //// tab | Python 3.7+
184-
185- ``` Python hl_lines="3 8 12 17"
186- # Code above omitted 👆
187-
188- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001.py[ln:104 - 109 ]!}
189-
190- # Code here omitted 👈
191-
192- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001.py[ln:158 - 163 ]!}
193-
194- # Code below omitted 👇
195- ```
196-
197- ////
65+ {* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py ln[ 156:161] hl=[ 3,8,12,17] * }
19866
19967/// details | 👀 Full file preview
20068
201- //// tab | Python 3.10+
202-
203- ``` Python
204- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py310.py!}
205- ```
206-
207- ////
208-
209- //// tab | Python 3.9+
210-
211- ``` Python
212- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001_py39.py!}
213- ```
214-
215- ////
216-
217- //// tab | Python 3.7+
218-
219- ``` Python
220- {!./ docs_src/ tutorial/ fastapi/ teams/ tutorial001.py!}
221- ```
222-
223- ////
224-
225- ///
69+ {* ./docs_src/tutorial/fastapi/teams/tutorial001_py310.py * }
22670
22771## Don't Include All the Data
22872
@@ -304,69 +148,12 @@ Let's add the models `HeroPublicWithTeam` and `TeamPublicWithHeroes`.
304148
305149We'll add them ** after** the other models so that we can easily reference the previous models.
306150
307- //// tab | Python 3.10+
308-
309- ``` Python hl_lines="3-4 7-8"
310- # Code above omitted 👆
311-
312- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py310.py[ln:59 - 64 ]!}
313-
314- # Code below omitted 👇
315- ```
316-
317- ////
318-
319- //// tab | Python 3.9+
320-
321- ``` Python hl_lines="3-4 7-8"
322- # Code above omitted 👆
323-
324- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py39.py[ln:61 - 66 ]!}
325-
326- # Code below omitted 👇
327- ```
328-
329- ////
330-
331- //// tab | Python 3.7+
332-
333- ``` Python hl_lines="3-4 7-8"
334- # Code above omitted 👆
335-
336- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001.py[ln:61 - 66 ]!}
337-
338- # Code below omitted 👇
339- ```
340-
341- ////
151+ {* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py ln[ 59-64] hl[ 3:4,7:8] * }
342152
343153/// details | 👀 Full file preview
344154
345- //// tab | Python 3.10+
346-
347- ``` Python
348- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py310.py!}
349- ```
350-
351- ////
352-
353- //// tab | Python 3.9+
354-
355- ``` Python
356- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py39.py!}
357- ```
358-
359- ////
360-
361- //// tab | Python 3.7+
362-
363- ``` Python
364- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001.py!}
365- ```
366-
367- ////
155+ {* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py * }
368156
369- ///
370157
371158These two models are very ** simple in code** , but there's a lot happening here. Let's check it out.
372159
@@ -400,81 +187,13 @@ This will tell **FastAPI** to take the object that we return from the *path oper
400187
401188In the case of the hero, this tells FastAPI to extract the ` team ` too. And in the case of the team, to extract the list of ` heroes ` too.
402189
403- //// tab | Python 3.10+
404-
405- ``` Python hl_lines="3 8 12 17"
406- # Code above omitted 👆
407-
408- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py310.py[ln:111 - 116 ]!}
409-
410- # Code here omitted 👈
411-
412- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py310.py[ln:165 - 170 ]!}
413-
414- # Code below omitted 👇
415- ```
416-
417- ////
418-
419- //// tab | Python 3.9+
420-
421- ``` Python hl_lines="3 8 12 17"
422- # Code above omitted 👆
423-
424- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py39.py[ln:113 - 118 ]!}
425-
426- # Code here omitted 👈
427-
428- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py39.py[ln:167 - 172 ]!}
429-
430- # Code below omitted 👇
431- ```
432-
433- ////
434-
435- //// tab | Python 3.7+
436-
437- ``` Python hl_lines="3 8 12 17"
438- # Code above omitted 👆
190+ {* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py ln[ 111:116] hl[ 3,8,12,17] * }
439191
440- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001.py[ln:113 - 118 ]!}
441-
442- # Code here omitted 👈
443-
444- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001.py[ln:167 - 172 ]!}
445-
446- # Code below omitted 👇
447- ```
448-
449- ////
192+ {* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py ln[ 165:170] hl[ 3,8,12,17] * }
450193
451194/// details | 👀 Full file preview
452195
453- //// tab | Python 3.10+
454-
455- ``` Python
456- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py310.py!}
457- ```
458-
459- ////
460-
461- //// tab | Python 3.9+
462-
463- ``` Python
464- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001_py39.py!}
465- ```
466-
467- ////
468-
469- //// tab | Python 3.7+
470-
471- ``` Python
472- {!./ docs_src/ tutorial/ fastapi/ relationships/ tutorial001.py!}
473- ```
474-
475- ////
476-
477- ///
196+ {* ./docs_src/tutorial/fastapi/relationships/tutorial001_py310.py * }
478197
479198## Check It Out in the Docs UI
480199
0 commit comments