fix scale and precision in decimal
This commit is contained in:
@ -44,7 +44,7 @@ class Item(ormar.Model):
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
category= ormar.ForeignKey(Category, nullable=True)
|
||||
category = ormar.ForeignKey(Category, nullable=True)
|
||||
|
||||
|
||||
@app.get("/items/", response_model=List[Item])
|
||||
|
||||
@ -14,8 +14,8 @@ class Department(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=100)
|
||||
|
||||
|
||||
class Course(ormar.Model):
|
||||
@ -23,10 +23,10 @@ class Course(ormar.Model):
|
||||
database = database
|
||||
metadata = metadata
|
||||
|
||||
id = ormar.Integer(primary_key=True)
|
||||
name = ormar.String(max_length=100)
|
||||
completed= ormar.Boolean(default=False)
|
||||
department= ormar.ForeignKey(Department)
|
||||
id: int = ormar.Integer(primary_key=True)
|
||||
name: str = ormar.String(max_length=100)
|
||||
completed: bool = ormar.Boolean(default=False)
|
||||
department: Optional[Department] = ormar.ForeignKey(Department)
|
||||
|
||||
|
||||
department = Department(name='Science')
|
||||
|
||||
@ -37,7 +37,7 @@ def ForeignKey( # noqa CFQ002
|
||||
virtual: bool = False,
|
||||
onupdate: str = None,
|
||||
ondelete: str = None,
|
||||
) -> Type["ForeignKeyField"]:
|
||||
) -> Any:
|
||||
fk_string = to.Meta.tablename + "." + to.get_column_alias(to.Meta.pkname)
|
||||
to_field = to.Meta.model_fields[to.Meta.pkname]
|
||||
__type__ = (
|
||||
|
||||
@ -17,7 +17,7 @@ def ManyToMany(
|
||||
unique: bool = False,
|
||||
virtual: bool = False,
|
||||
**kwargs: Any
|
||||
) -> Type["ManyToManyField"]:
|
||||
) -> Any:
|
||||
to_field = to.Meta.model_fields[to.Meta.pkname]
|
||||
related_name = kwargs.pop("related_name", None)
|
||||
nullable = kwargs.pop("nullable", True)
|
||||
@ -50,7 +50,7 @@ def ManyToMany(
|
||||
class ManyToManyField(ForeignKeyField):
|
||||
through: Type["Model"]
|
||||
|
||||
if TYPE_CHECKING: # noqa: C901; pragma nocover
|
||||
if TYPE_CHECKING: # noqa: C901; #pragma nocover
|
||||
|
||||
@staticmethod
|
||||
async def add(item: "Model") -> None:
|
||||
|
||||
@ -292,14 +292,14 @@ class Decimal(ModelFieldFactory, decimal.Decimal):
|
||||
kwargs["le"] = kwargs["maximum"]
|
||||
|
||||
if kwargs.get("max_digits"):
|
||||
kwargs["scale"] = kwargs["max_digits"]
|
||||
elif kwargs.get("scale"):
|
||||
kwargs["max_digits"] = kwargs["scale"]
|
||||
kwargs["precision"] = kwargs["max_digits"]
|
||||
elif kwargs.get("precision"):
|
||||
kwargs["max_digits"] = kwargs["precision"]
|
||||
|
||||
if kwargs.get("decimal_places"):
|
||||
kwargs["precision"] = kwargs["decimal_places"]
|
||||
elif kwargs.get("precision"):
|
||||
kwargs["decimal_places"] = kwargs["precision"]
|
||||
kwargs["scale"] = kwargs["decimal_places"]
|
||||
elif kwargs.get("scale"):
|
||||
kwargs["decimal_places"] = kwargs["scale"]
|
||||
|
||||
return super().__new__(cls, **kwargs)
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ class ExampleModel(Model):
|
||||
test_time = ormar.Time(default=datetime.time)
|
||||
test_json = ormar.JSON(default={})
|
||||
test_bigint = ormar.BigInteger(default=0)
|
||||
test_decimal = ormar.Decimal(scale=10, precision=2)
|
||||
test_decimal = ormar.Decimal(scale=2, precision=10)
|
||||
test_decimal2 = ormar.Decimal(max_digits=10, decimal_places=2)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user