@@ -80,45 +80,7 @@ We don't call `uuid.uuid4()` ourselves in the code (we don't put the parenthesis
80
80
81
81
This means that the UUID will be generated in the Python code, ** before sending the data to the database** .
82
82
83
- //// tab | Python 3.10+
84
-
85
- ``` Python hl_lines="1 7"
86
- {!./ docs_src/ advanced/ uuid/ tutorial001_py310.py[ln:1 - 10 ]!}
87
-
88
- # Code below omitted 👇
89
- ```
90
-
91
- ////
92
-
93
- //// tab | Python 3.7+
94
-
95
- ``` Python hl_lines="1 8"
96
- {!./ docs_src/ advanced/ uuid/ tutorial001.py[ln:1 - 11 ]!}
97
-
98
- # Code below omitted 👇
99
- ```
100
-
101
- ////
102
-
103
- /// details | 👀 Full file preview
104
-
105
- //// tab | Python 3.10+
106
-
107
- ``` Python
108
- {!./ docs_src/ advanced/ uuid/ tutorial001_py310.py!}
109
- ```
110
-
111
- ////
112
-
113
- //// tab | Python 3.7+
114
-
115
- ``` Python
116
- {!./ docs_src/ advanced/ uuid/ tutorial001.py!}
117
- ```
118
-
119
- ////
120
-
121
- ///
83
+ {* ./docs_src/advanced/uuid/tutorial001_py310.py ln[ 1:10] hl[ 1,7] * }
122
84
123
85
Pydantic has support for <a href =" https://docs.pydantic.dev/latest/api/standard_library_types/#uuid " class =" external-link " target =" _blank " >` UUID ` types</a >.
124
86
@@ -132,99 +94,15 @@ As `uuid.uuid4` will be called when creating the model instance, even before sen
132
94
133
95
And that ** same ID (a UUID)** will be saved in the database.
134
96
135
- //// tab | Python 3.10+
136
-
137
- ``` Python hl_lines="5 7 9 14"
138
- # Code above omitted 👆
139
-
140
- {!./ docs_src/ advanced/ uuid/ tutorial001_py310.py[ln:23 - 34 ]!}
141
-
142
- # Code below omitted 👇
143
- ```
144
-
145
- ////
146
-
147
- //// tab | Python 3.7+
148
-
149
- ``` Python hl_lines="5 7 9 14"
150
- # Code above omitted 👆
151
-
152
- {!./ docs_src/ advanced/ uuid/ tutorial001.py[ln:24 - 35 ]!}
153
-
154
- # Code below omitted 👇
155
- ```
156
-
157
- ////
158
-
159
- /// details | 👀 Full file preview
160
-
161
- //// tab | Python 3.10+
162
-
163
- ``` Python
164
- {!./ docs_src/ advanced/ uuid/ tutorial001_py310.py!}
165
- ```
166
-
167
- ////
168
-
169
- //// tab | Python 3.7+
170
-
171
- ``` Python
172
- {!./ docs_src/ advanced/ uuid/ tutorial001.py!}
173
- ```
174
-
175
- ////
176
-
177
- ///
97
+ {* ./docs_src/advanced/uuid/tutorial001_py310.py ln[ 23:34] hl[ 25,27,29,34] * }
178
98
179
99
### Select a Hero
180
100
181
101
We can do the same operations we could do with other fields.
182
102
183
103
For example we can ** select a hero by ID** :
184
104
185
- //// tab | Python 3.10+
186
-
187
- ``` Python hl_lines="15"
188
- # Code above omitted 👆
189
-
190
- {!./ docs_src/ advanced/ uuid/ tutorial001_py310.py[ln:37 - 54 ]!}
191
-
192
- # Code below omitted 👇
193
- ```
194
-
195
- ////
196
-
197
- //// tab | Python 3.7+
198
-
199
- ``` Python hl_lines="15"
200
- # Code above omitted 👆
201
-
202
- {!./ docs_src/ advanced/ uuid/ tutorial001.py[ln:38 - 55 ]!}
203
-
204
- # Code below omitted 👇
205
- ```
206
-
207
- ////
208
-
209
- /// details | 👀 Full file preview
210
-
211
- //// tab | Python 3.10+
212
-
213
- ``` Python
214
- {!./ docs_src/ advanced/ uuid/ tutorial001_py310.py!}
215
- ```
216
-
217
- ////
218
-
219
- //// tab | Python 3.7+
220
-
221
- ``` Python
222
- {!./ docs_src/ advanced/ uuid/ tutorial001.py!}
223
- ```
224
-
225
- ////
226
-
227
- ///
105
+ {* ./docs_src/advanced/uuid/tutorial001_py310.py ln[ 37:54] hl[ 49] * }
228
106
229
107
/// tip
230
108
@@ -238,49 +116,7 @@ SQLModel (actually SQLAlchemy) will take care of making it work. ✨
238
116
239
117
We could also select by ID with ` session.get() ` :
240
118
241
- //// tab | Python 3.10+
242
-
243
- ``` Python hl_lines="15"
244
- # Code above omitted 👆
245
-
246
- {!./ docs_src/ advanced/ uuid/ tutorial002_py310.py[ln:37 - 54 ]!}
247
-
248
- # Code below omitted 👇
249
- ```
250
-
251
- ////
252
-
253
- //// tab | Python 3.7+
254
-
255
- ``` Python hl_lines="15"
256
- # Code above omitted 👆
257
-
258
- {!./ docs_src/ advanced/ uuid/ tutorial002.py[ln:38 - 55 ]!}
259
-
260
- # Code below omitted 👇
261
- ```
262
-
263
- ////
264
-
265
- /// details | 👀 Full file preview
266
-
267
- //// tab | Python 3.10+
268
-
269
- ``` Python
270
- {!./ docs_src/ advanced/ uuid/ tutorial002_py310.py!}
271
- ```
272
-
273
- ////
274
-
275
- //// tab | Python 3.7+
276
-
277
- ``` Python
278
- {!./ docs_src/ advanced/ uuid/ tutorial002.py!}
279
- ```
280
-
281
- ////
282
-
283
- ///
119
+ {* ./docs_src/advanced/uuid/tutorial002_py310.py ln[ 37:53] hl[ 49] * }
284
120
285
121
The same way as with other fields, we could update, delete, etc. 🚀
286
122
0 commit comments