Skip to content

Commit aab35d7

Browse files
committed
Update docs/tutorial/fastapi/update-extra-data.md
1 parent 893f8bd commit aab35d7

File tree

1 file changed

+10
-302
lines changed

1 file changed

+10
-302
lines changed

docs/tutorial/fastapi/update-extra-data.md

Lines changed: 10 additions & 302 deletions
Original file line numberDiff line numberDiff line change
@@ -38,67 +38,11 @@ The `Hero` table model will now store a new field `hashed_password`.
3838

3939
And the data models for `HeroCreate` and `HeroUpdate` will also have a new field `password` that will contain the plain text password sent by clients.
4040

41-
//// tab | Python 3.10+
42-
43-
```Python hl_lines="11 15 26"
44-
# Code above omitted 👆
45-
46-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:5-28]!}
47-
48-
# Code below omitted 👇
49-
```
50-
51-
////
52-
53-
//// tab | Python 3.9+
54-
55-
```Python hl_lines="11 15 26"
56-
# Code above omitted 👆
57-
58-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:7-30]!}
59-
60-
# Code below omitted 👇
61-
```
62-
63-
////
64-
65-
//// tab | Python 3.7+
66-
67-
```Python hl_lines="11 15 26"
68-
# Code above omitted 👆
69-
70-
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:7-30]!}
71-
72-
# Code below omitted 👇
73-
```
74-
75-
////
41+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[5:28] hl[11,15,26] *}
7642

7743
/// details | 👀 Full file preview
7844

79-
//// tab | Python 3.10+
80-
81-
```Python
82-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
83-
```
84-
85-
////
86-
87-
//// tab | Python 3.9+
88-
89-
```Python
90-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
91-
```
92-
93-
////
94-
95-
//// tab | Python 3.7+
96-
97-
```Python
98-
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
99-
```
100-
101-
////
45+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py *}
10246

10347
///
10448

@@ -112,79 +56,11 @@ The app will receive the data from the client using the `HeroCreate` model.
11256

11357
This contains the `password` field with the plain text password, and we cannot use that one. So we need to generate a hash from it.
11458

115-
//// tab | Python 3.10+
116-
117-
```Python hl_lines="11"
118-
# Code above omitted 👆
119-
120-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:42-44]!}
121-
122-
# Code here omitted 👈
123-
124-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:55-57]!}
125-
126-
# Code below omitted 👇
127-
```
128-
129-
////
130-
131-
//// tab | Python 3.9+
132-
133-
```Python hl_lines="11"
134-
# Code above omitted 👆
135-
136-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:44-46]!}
137-
138-
# Code here omitted 👈
139-
140-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:57-59]!}
141-
142-
# Code below omitted 👇
143-
```
144-
145-
////
146-
147-
//// tab | Python 3.7+
148-
149-
```Python hl_lines="11"
150-
# Code above omitted 👆
151-
152-
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:44-46]!}
153-
154-
# Code here omitted 👈
155-
156-
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:57-59]!}
157-
158-
# Code below omitted 👇
159-
```
160-
161-
////
59+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[42:44] hl[11] *}
16260

16361
/// details | 👀 Full file preview
16462

165-
//// tab | Python 3.10+
166-
167-
```Python
168-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
169-
```
170-
171-
////
172-
173-
//// tab | Python 3.9+
174-
175-
```Python
176-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
177-
```
178-
179-
////
180-
181-
//// tab | Python 3.7+
182-
183-
```Python
184-
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
185-
```
186-
187-
////
63+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py *}
18864

18965
///
19066

@@ -242,67 +118,11 @@ So now, `db_user_dict` has the updated `age` field with `32` instead of `None` a
242118

243119
Similar to how dictionaries have an `update` method, **SQLModel** models have a parameter `update` in `Hero.model_validate()` that takes a dictionary with extra data, or data that should take precedence:
244120

245-
//// tab | Python 3.10+
246-
247-
```Python hl_lines="8"
248-
# Code above omitted 👆
249-
250-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:55-64]!}
251-
252-
# Code below omitted 👇
253-
```
254-
255-
////
256-
257-
//// tab | Python 3.9+
258-
259-
```Python hl_lines="8"
260-
# Code above omitted 👆
261-
262-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:57-66]!}
263-
264-
# Code below omitted 👇
265-
```
266-
267-
////
268-
269-
//// tab | Python 3.7+
270-
271-
```Python hl_lines="8"
272-
# Code above omitted 👆
273-
274-
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:57-66]!}
275-
276-
# Code below omitted 👇
277-
```
278-
279-
////
121+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[55:64] hl[8] *}
280122

281123
/// details | 👀 Full file preview
282124

283-
//// tab | Python 3.10+
284-
285-
```Python
286-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
287-
```
288-
289-
////
290-
291-
//// tab | Python 3.9+
292-
293-
```Python
294-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
295-
```
296-
297-
////
298-
299-
//// tab | Python 3.7+
300-
301-
```Python
302-
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
303-
```
304-
305-
////
125+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py *}
306126

307127
///
308128

@@ -318,67 +138,11 @@ Now let's say we want to **update a hero** that already exists in the database.
318138

319139
The same way as before, to avoid removing existing data, we will use `exclude_unset=True` when calling `hero.model_dump()`, to get a dictionary with only the data sent by the client.
320140

321-
//// tab | Python 3.10+
322-
323-
```Python hl_lines="9"
324-
# Code above omitted 👆
325-
326-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:83-89]!}
327-
328-
# Code below omitted 👇
329-
```
330-
331-
////
332-
333-
//// tab | Python 3.9+
334-
335-
```Python hl_lines="9"
336-
# Code above omitted 👆
337-
338-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:85-91]!}
339-
340-
# Code below omitted 👇
341-
```
342-
343-
////
344-
345-
//// tab | Python 3.7+
346-
347-
```Python hl_lines="9"
348-
# Code above omitted 👆
349-
350-
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:85-91]!}
351-
352-
# Code below omitted 👇
353-
```
354-
355-
////
141+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[83:89] hl[9] *}
356142

357143
/// details | 👀 Full file preview
358144

359-
//// tab | Python 3.10+
360-
361-
```Python
362-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
363-
```
364-
365-
////
366-
367-
//// tab | Python 3.9+
368-
369-
```Python
370-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
371-
```
372-
373-
////
374-
375-
//// tab | Python 3.7+
376-
377-
```Python
378-
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
379-
```
380-
381-
////
145+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py *}
382146

383147
///
384148

@@ -390,67 +154,11 @@ And then we can update the `db_hero` object using the method `db_hero.sqlmodel_u
390154

391155
It takes a model object or dictionary with the data to update the object and also an **additional `update` argument** with extra data.
392156

393-
//// tab | Python 3.10+
394-
395-
```Python hl_lines="15"
396-
# Code above omitted 👆
397-
398-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py[ln:83-99]!}
399-
400-
# Code below omitted 👇
401-
```
402-
403-
////
404-
405-
//// tab | Python 3.9+
406-
407-
```Python hl_lines="15"
408-
# Code above omitted 👆
409-
410-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py[ln:85-101]!}
411-
412-
# Code below omitted 👇
413-
```
414-
415-
////
416-
417-
//// tab | Python 3.7+
418-
419-
```Python hl_lines="15"
420-
# Code above omitted 👆
421-
422-
{!./docs_src/tutorial/fastapi/update/tutorial002.py[ln:85-101]!}
423-
424-
# Code below omitted 👇
425-
```
426-
427-
////
157+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py ln[83:99] hl[15] *}
428158

429159
/// details | 👀 Full file preview
430160

431-
//// tab | Python 3.10+
432-
433-
```Python
434-
{!./docs_src/tutorial/fastapi/update/tutorial002_py310.py!}
435-
```
436-
437-
////
438-
439-
//// tab | Python 3.9+
440-
441-
```Python
442-
{!./docs_src/tutorial/fastapi/update/tutorial002_py39.py!}
443-
```
444-
445-
////
446-
447-
//// tab | Python 3.7+
448-
449-
```Python
450-
{!./docs_src/tutorial/fastapi/update/tutorial002.py!}
451-
```
452-
453-
////
161+
{* ./docs_src/tutorial/fastapi/update/tutorial002_py310.py *}
454162

455163
///
456164

0 commit comments

Comments
 (0)