Skip to content

Commit 3bb988b

Browse files
committed
Add a decimal attribute in code structure tutorial and test
1 parent 5756e8f commit 3bb988b

6 files changed

Lines changed: 9 additions & 3 deletions

File tree

docs_src/tutorial/code_structure/tutorial001/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def create_heroes():
99
team_z_force = Team(name="Z-Force", headquarters="Sister Margaret’s Bar")
1010

1111
hero_deadpond = Hero(
12-
name="Deadpond", secret_name="Dive Wilson", team=team_z_force
12+
name="Deadpond", secret_name="Dive Wilson", team=team_z_force, experience_points=1
1313
)
1414
session.add(hero_deadpond)
1515
session.commit()

docs_src/tutorial/code_structure/tutorial001/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from pydantic import condecimal
12
from typing import List, Optional
23

34
from sqlmodel import Field, Relationship, SQLModel
45

5-
66
class Team(SQLModel, table=True):
77
id: Optional[int] = Field(default=None, primary_key=True)
88
name: str
@@ -16,6 +16,7 @@ class Hero(SQLModel, table=True):
1616
name: str
1717
secret_name: str
1818
age: Optional[int] = None
19+
experience_points: condecimal(max_digits=6, decimal_places=3) = Field(default=0, nullable=False, index=True)
1920

2021
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
2122
team: Optional[Team] = Relationship(back_populates="heroes")

docs_src/tutorial/code_structure/tutorial002/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def create_heroes():
1010
team_z_force = Team(name="Z-Force", headquarters="Sister Margaret’s Bar")
1111

1212
hero_deadpond = Hero(
13-
name="Deadpond", secret_name="Dive Wilson", team=team_z_force
13+
name="Deadpond", secret_name="Dive Wilson", team=team_z_force, experience_points=1
1414
)
1515
session.add(hero_deadpond)
1616
session.commit()

docs_src/tutorial/code_structure/tutorial002/hero_model.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pydantic import condecimal
12
from typing import TYPE_CHECKING, Optional
23

34
from sqlmodel import Field, Relationship, SQLModel
@@ -11,6 +12,7 @@ class Hero(SQLModel, table=True):
1112
name: str
1213
secret_name: str
1314
age: Optional[int] = None
15+
experience_points: condecimal(max_digits=6, decimal_places=3) = Field(default=0, nullable=False, index=True)
1416

1517
team_id: Optional[int] = Field(default=None, foreign_key="team.id")
1618
team: Optional["Team"] = Relationship(back_populates="heroes")

tests/test_tutorial/test_code_structure/test_tutorial001.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from ...conftest import get_testing_print_function
66

7+
78
expected_calls = [
89
[
910
"Created hero:",
@@ -13,6 +14,7 @@
1314
"age": None,
1415
"secret_name": "Dive Wilson",
1516
"team_id": 1,
17+
"experience_points": 1,
1618
},
1719
],
1820
[

tests/test_tutorial/test_code_structure/test_tutorial002.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"age": None,
1414
"secret_name": "Dive Wilson",
1515
"team_id": 1,
16+
"experience_points": 1,
1617
},
1718
],
1819
[

0 commit comments

Comments
 (0)