From: Sebastián Ramírez Date: Mon, 4 Dec 2023 09:49:23 +0000 (+0100) Subject: 📝 Update docs for Decimal, use proper types (#719) X-Git-Tag: 0.0.13~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41495e30c7509b2d23b6673017b3d2b14a36b26b;p=thirdparty%2Ffastapi%2Fsqlmodel.git 📝 Update docs for Decimal, use proper types (#719) --- diff --git a/docs/advanced/decimal.md b/docs/advanced/decimal.md index 036aae00..2b58550d 100644 --- a/docs/advanced/decimal.md +++ b/docs/advanced/decimal.md @@ -19,21 +19,13 @@ In most cases this would probably not be a problem, for example measuring views ## Decimal Types -Pydantic has special support for `Decimal` types using the `condecimal()` special function. +Pydantic has special support for `Decimal` types. -/// tip - -Pydantic 1.9, that will be released soon, has improved support for `Decimal` types, without needing to use the `condecimal()` function. - -But meanwhile, you can already use this feature with `condecimal()` in **SQLModel** it as it's explained here. - -/// - -When you use `condecimal()` you can specify the number of digits and decimal places to support. They will be validated by Pydantic (for example when using FastAPI) and the same information will also be used for the database columns. +When you use `Decimal` you can specify the number of digits and decimal places to support in the `Field()` function. They will be validated by Pydantic (for example when using FastAPI) and the same information will also be used for the database columns. /// info -For the database, **SQLModel** will use SQLAlchemy's `DECIMAL` type. +For the database, **SQLModel** will use SQLAlchemy's `DECIMAL` type. /// diff --git a/docs_src/advanced/decimal/tutorial001.py b/docs_src/advanced/decimal/tutorial001.py index b803119d..a0a9804a 100644 --- a/docs_src/advanced/decimal/tutorial001.py +++ b/docs_src/advanced/decimal/tutorial001.py @@ -1,6 +1,6 @@ +from decimal import Decimal from typing import Optional -from pydantic import condecimal from sqlmodel import Field, Session, SQLModel, create_engine, select @@ -9,7 +9,7 @@ class Hero(SQLModel, table=True): name: str = Field(index=True) secret_name: str age: Optional[int] = Field(default=None, index=True) - money: condecimal(max_digits=5, decimal_places=3) = Field(default=0) + money: Decimal = Field(default=0, max_digits=5, decimal_places=3) sqlite_file_name = "database.db" diff --git a/docs_src/advanced/decimal/tutorial001_py310.py b/docs_src/advanced/decimal/tutorial001_py310.py index 92afc090..26733891 100644 --- a/docs_src/advanced/decimal/tutorial001_py310.py +++ b/docs_src/advanced/decimal/tutorial001_py310.py @@ -1,4 +1,5 @@ -from pydantic import condecimal +from decimal import Decimal + from sqlmodel import Field, Session, SQLModel, create_engine, select @@ -7,7 +8,7 @@ class Hero(SQLModel, table=True): name: str = Field(index=True) secret_name: str age: int | None = Field(default=None, index=True) - money: condecimal(max_digits=5, decimal_places=3) = Field(default=0) + money: Decimal = Field(default=0, max_digits=5, decimal_places=3) sqlite_file_name = "database.db"