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