FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

📝 Update markdown includes format by tiangolo · Pull Request #1254 · fastapi/sqlmodel · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (38) .txt  (1) All 2 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
128 changes: 3 additions & 125 deletions docs/advanced/decimal.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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

Expand Down
Loading

Back | FazBrowse Home | New Git URL