@@ -33,45 +33,7 @@ For the database, **SQLModel** will use <a href="https://docs.sqlalchemy.org/en/
3333
3434Let's say that each hero in the database will have an amount of money. We could make that field a ` Decimal ` type using the ` condecimal() ` function:
3535
36- //// tab | Python 3.10+
37-
38- ``` Python hl_lines="11"
39- {!./ docs_src/ advanced/ decimal/ tutorial001_py310.py[ln:1 - 11 ]!}
40-
41- # More code here later 👇
42- ```
43-
44- ////
45-
46- //// tab | Python 3.7+
47-
48- ``` Python hl_lines="12"
49- {!./ docs_src/ advanced/ decimal/ tutorial001.py[ln:1 - 12 ]!}
50-
51- # More code here later 👇
52- ```
53-
54- ////
55-
56- /// details | 👀 Full file preview
57-
58- //// tab | Python 3.10+
59-
60- ``` Python
61- {!./ docs_src/ advanced/ decimal/ tutorial001_py310.py!}
62- ```
63-
64- ////
65-
66- //// tab | Python 3.7+
67-
68- ``` Python
69- {!./ docs_src/ advanced/ decimal/ tutorial001.py!}
70- ```
71-
72- ////
73-
74- ///
36+ {* ./docs_src/advanced/decimal/tutorial001_py310.py ln[ 1:11] hl[ 11] * }
7537
7638Here we are saying that ` money ` can have at most ` 5 ` digits with ` max_digits ` , ** this includes the integers** (to the left of the decimal dot) ** and the decimals** (to the right of the decimal dot).
7739
@@ -105,97 +67,13 @@ Make sure you adjust the number of digits and decimal places for your own needs,
10567
10668When creating new models you can actually pass normal (` float ` ) numbers, Pydantic will automatically convert them to ` Decimal ` types, and ** SQLModel** will store them as ` Decimal ` types in the database (using SQLAlchemy).
10769
108- //// tab | Python 3.10+
109-
110- ``` Python hl_lines="4-6"
111- # Code above omitted 👆
112-
113- {!./ docs_src/ advanced/ decimal/ tutorial001_py310.py[ln:24 - 34 ]!}
114-
115- # Code below omitted 👇
116- ```
117-
118- ////
119-
120- //// tab | Python 3.7+
121-
122- ``` Python hl_lines="4-6"
123- # Code above omitted 👆
124-
125- {!./ docs_src/ advanced/ decimal/ tutorial001.py[ln:25 - 35 ]!}
126-
127- # Code below omitted 👇
128- ```
129-
130- ////
131-
132- /// details | 👀 Full file preview
133-
134- //// tab | Python 3.10+
135-
136- ``` Python
137- {!./ docs_src/ advanced/ decimal/ tutorial001_py310.py!}
138- ```
139-
140- ////
141-
142- //// tab | Python 3.7+
143-
144- ``` Python
145- {!./ docs_src/ advanced/ decimal/ tutorial001.py!}
146- ```
147-
148- ////
149-
150- ///
70+ {* ./docs_src/advanced/decimal/tutorial001_py310.py ln[ 24:34] hl[ 25:27] * }
15171
15272## Select Decimal data
15373
15474Then, when working with Decimal types, you can confirm that they indeed avoid those rounding errors from floats:
15575
156- //// tab | Python 3.10+
157-
158- ``` Python hl_lines="15-16"
159- # Code above omitted 👆
160-
161- {!./ docs_src/ advanced/ decimal/ tutorial001_py310.py[ln:37 - 50 ]!}
162-
163- # Code below omitted 👇
164- ```
165-
166- ////
167-
168- //// tab | Python 3.7+
169-
170- ``` Python hl_lines="15-16"
171- # Code above omitted 👆
172-
173- {!./ docs_src/ advanced/ decimal/ tutorial001.py[ln:38 - 51 ]!}
174-
175- # Code below omitted 👇
176- ```
177-
178- ////
179-
180- /// details | 👀 Full file preview
181-
182- //// tab | Python 3.10+
183-
184- ``` Python
185- {!./ docs_src/ advanced/ decimal/ tutorial001_py310.py!}
186- ```
187-
188- ////
189-
190- //// tab | Python 3.7+
191-
192- ``` Python
193- {!./ docs_src/ advanced/ decimal/ tutorial001.py!}
194- ```
195-
196- ////
197-
198- ///
76+ {* ./docs_src/advanced/decimal/tutorial001_py310.py ln[ 37:50] hl[ 49:50] * }
19977
20078## Review the results
20179
0 commit comments