diff --git a/docs/contrib/pydantic.rst b/docs/contrib/pydantic.rst
index 0d4e7d5c3..a77d5ba2c 100644
--- a/docs/contrib/pydantic.rst
+++ b/docs/contrib/pydantic.rst
@@ -25,7 +25,7 @@ Here we introduce:
* Creating a Pydantic model from a Tortoise model
* Docstrings & doc-comments are used
* Evaluating the generated schema
-* Simple serialisation with both ``.dict()`` and ``.json()``
+* Simple serialisation with both ``.model_dump()`` and ``.model_dump_json()``
Source to example: :ref:`example_pydantic_tut1`
@@ -92,17 +92,17 @@ To serialise an object it is simply *(in an async context)*:
tournament = await Tournament.create(name="New Tournament")
tourpy = await Tournament_Pydantic.from_tortoise_orm(tournament)
-And one could get the contents by using `regular Pydantic-object methods `_, such as ``.dict()`` or ``.json()``
+And one could get the contents by using `regular Pydantic-object methods `_, such as ``.model_dump()`` or ``.model_dump_json()``
.. code-block:: py3
- >>> print(tourpy.dict())
+ >>> print(tourpy.model_dump())
{
'id': 1,
'name': 'New Tournament',
'created_at': datetime.datetime(2020, 3, 1, 20, 28, 9, 346808)
}
- >>> print(tourpy.json())
+ >>> print(tourpy.model_dump_json())
{
"id": 1,
"name": "New Tournament",
@@ -202,13 +202,13 @@ To serialise an object it is simply *(in an async context)*:
tourpy = await Tournament_Pydantic_List.from_queryset(Tournament.all())
-And one could get the contents by using `regular Pydantic-object methods `_, such as ``.dict()`` or ``.json()``
+And one could get the contents by using `regular Pydantic-object methods `_, such as ``.model_dump()`` or ``.model_dump_json()``
.. code-block:: py3
- >>> print(tourpy.dict())
+ >>> print(tourpy.model_dump())
{
- '__root__': [
+ 'root': [
{
'id': 2,
'name': 'Another',
@@ -226,7 +226,7 @@ And one could get the contents by using `regular Pydantic-object methods >> print(tourpy.json())
+ >>> print(tourpy.model_dump_json())
[
{
"id": 2,
@@ -245,7 +245,7 @@ And one could get the contents by using `regular Pydantic-object methods >> print(tourpy.json())
+ >>> print(tourpy.model_dump_json())
{
"id": 1,
"name": "New Tournament",
@@ -499,7 +499,7 @@ And serialising the event *(in an async context)*:
eventpy = await Event_Pydantic.from_tortoise_orm(event)
- >>> print(eventpy.json())
+ >>> print(eventpy.model_dump_json())
{
"id": 1,
"name": "The Event",
@@ -675,7 +675,7 @@ Lets create and serialise the objects and see what they look like *(in an async
# Serialise Tournament
tourpy = await Tournament_Pydantic.from_tortoise_orm(tournament)
- >>> print(tourpy.json())
+ >>> print(tourpy.model_dump_json())
{
"id": 1,
"name": "New Tournament",
diff --git a/examples/blacksheep/server.py b/examples/blacksheep/server.py
index 970ad1e14..489520c64 100644
--- a/examples/blacksheep/server.py
+++ b/examples/blacksheep/server.py
@@ -43,7 +43,7 @@ async def users_patch(id: UUID, user: UserPydanticIn) -> UserPydanticOut:
@app.router.put("/{id}")
async def users_put(id: UUID, user: UserPydanticIn) -> UserPydanticOut:
- await Users.filter(id=id).update(**user.dict())
+ await Users.filter(id=id).update(**user.model_dump())
return ok(await UserPydanticOut.from_tortoise_orm(await Users.get(id=id)))
diff --git a/examples/pydantic/tutorial_1.py b/examples/pydantic/tutorial_1.py
index b3533650b..e0becf55f 100644
--- a/examples/pydantic/tutorial_1.py
+++ b/examples/pydantic/tutorial_1.py
@@ -5,7 +5,7 @@
* Creating a Pydantic model from a Tortoise model
* Docstrings & doc-comments are used
* Evaluating the generated schema
-* Simple serialisation with both .dict() and .json()
+* Simple serialisation with both .model_dump() and .model_dump_json()
"""
from tortoise import Tortoise, fields, run_async
from tortoise.contrib.pydantic import pydantic_model_creator
@@ -38,7 +38,7 @@ async def run():
tourpy = await Tournament_Pydantic.from_tortoise_orm(tournament)
# As Python dict with Python objects (e.g. datetime)
- print(tourpy.dict())
+ print(tourpy.model_dump())
# As serialised JSON (e.g. datetime is ISO8601 string representation)
print(tourpy.json(indent=4))
diff --git a/examples/pydantic/tutorial_2.py b/examples/pydantic/tutorial_2.py
index ee6bf0e0c..64ef8fdcb 100644
--- a/examples/pydantic/tutorial_2.py
+++ b/examples/pydantic/tutorial_2.py
@@ -45,8 +45,8 @@ async def run():
tourpy = await Tournament_Pydantic_List.from_queryset(Tournament.all())
# As Python dict with Python objects (e.g. datetime)
- # Note that the root element is '__root__' that contains the root element.
- print(tourpy.dict())
+ # Note that the root element is 'root' that contains the root element.
+ print(tourpy.model_dump())
# As serialised JSON (e.g. datetime is ISO8601 string representation)
print(tourpy.json(indent=4))