📝 Update markdown includes format (#1254)
This commit is contained in:
committed by
GitHub
parent
0c65fed61b
commit
5100200bea
@@ -33,45 +33,7 @@ For the database, **SQLModel** will use <a href="https://docs.sqlalchemy.org/en/
|
||||
|
||||
Let'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:
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python hl_lines="11"
|
||||
{!./docs_src/advanced/decimal/tutorial001_py310.py[ln:1-11]!}
|
||||
|
||||
# More code here later 👇
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.7+
|
||||
|
||||
```Python hl_lines="12"
|
||||
{!./docs_src/advanced/decimal/tutorial001.py[ln:1-12]!}
|
||||
|
||||
# More code here later 👇
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
/// details | 👀 Full file preview
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python
|
||||
{!./docs_src/advanced/decimal/tutorial001_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.7+
|
||||
|
||||
```Python
|
||||
{!./docs_src/advanced/decimal/tutorial001.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
///
|
||||
{* ./docs_src/advanced/decimal/tutorial001_py310.py ln[1:11] hl[11] *}
|
||||
|
||||
Here 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).
|
||||
|
||||
@@ -105,97 +67,13 @@ Make sure you adjust the number of digits and decimal places for your own needs,
|
||||
|
||||
When 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).
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python hl_lines="4-6"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/advanced/decimal/tutorial001_py310.py[ln:24-34]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.7+
|
||||
|
||||
```Python hl_lines="4-6"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/advanced/decimal/tutorial001.py[ln:25-35]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
/// details | 👀 Full file preview
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python
|
||||
{!./docs_src/advanced/decimal/tutorial001_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.7+
|
||||
|
||||
```Python
|
||||
{!./docs_src/advanced/decimal/tutorial001.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
///
|
||||
{* ./docs_src/advanced/decimal/tutorial001_py310.py ln[24:34] hl[25:27] *}
|
||||
|
||||
## Select Decimal data
|
||||
|
||||
Then, when working with Decimal types, you can confirm that they indeed avoid those rounding errors from floats:
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python hl_lines="15-16"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/advanced/decimal/tutorial001_py310.py[ln:37-50]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.7+
|
||||
|
||||
```Python hl_lines="15-16"
|
||||
# Code above omitted 👆
|
||||
|
||||
{!./docs_src/advanced/decimal/tutorial001.py[ln:38-51]!}
|
||||
|
||||
# Code below omitted 👇
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
/// details | 👀 Full file preview
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python
|
||||
{!./docs_src/advanced/decimal/tutorial001_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.7+
|
||||
|
||||
```Python
|
||||
{!./docs_src/advanced/decimal/tutorial001.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
///
|
||||
{* ./docs_src/advanced/decimal/tutorial001_py310.py ln[37:50] hl[49:50] *}
|
||||
|
||||
## Review the results
|
||||
|
||||
|
||||
Reference in New Issue
Block a user