|
def | __init__ (self, typing.Optional[int] places=None, typing.Optional[str] rounding=None, *bool allow_nan=False, bool as_string=False, **kwargs) |
|
def | __init__ (self, *bool as_string=False, **kwargs) |
|
None | __init__ (self, *typing.Any default=missing_, typing.Any missing=missing_, typing.Optional[str] data_key=None, typing.Optional[str] attribute=None, typing.Optional[typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]],]] validate=None, bool required=False, typing.Optional[bool] allow_none=None, bool load_only=False, bool dump_only=False, typing.Optional[typing.Dict[str, str]] error_messages=None, typing.Optional[typing.Mapping[str, typing.Any]] metadata=None, **additional_metadata) |
|
str | __repr__ (self) |
|
def | __deepcopy__ (self, memo) |
|
def | get_value (self, obj, attr, accessor=None, default=missing_) |
|
ValidationError | make_error (self, str key, **kwargs) |
|
def | fail (self, str key, **kwargs) |
|
def | serialize (self, str attr, typing.Any obj, typing.Optional[typing.Callable[[typing.Any, str, typing.Any], typing.Any]] accessor=None, **kwargs) |
|
def | deserialize (self, typing.Any value, typing.Optional[str] attr=None, typing.Optional[typing.Mapping[str, typing.Any]] data=None, **kwargs) |
|
def | context (self) |
|
def | serialize (self, attr, obj, accessor=None) |
|
def | deserialize (self, value) |
|
A field that (de)serializes to the Python ``decimal.Decimal`` type.
It's safe to use when dealing with money values, percentages, ratios
or other numbers where precision is critical.
.. warning::
This field serializes to a `decimal.Decimal` object by default. If you need
to render your data as JSON, keep in mind that the `json` module from the
standard library does not encode `decimal.Decimal`. Therefore, you must use
a JSON library that can handle decimals, such as `simplejson`, or serialize
to a string by passing ``as_string=True``.
.. warning::
If a JSON `float` value is passed to this field for deserialization it will
first be cast to its corresponding `string` value before being deserialized
to a `decimal.Decimal` object. The default `__str__` implementation of the
built-in Python `float` type may apply a destructive transformation upon
its input data and therefore cannot be relied upon to preserve precision.
To avoid this, you can instead pass a JSON `string` to be deserialized
directly.
:param places: How many decimal places to quantize the value. If `None`, does
not quantize the value.
:param rounding: How to round the value during quantize, for example
`decimal.ROUND_UP`. If `None`, uses the rounding value from
the current thread's context.
:param allow_nan: If `True`, `NaN`, `Infinity` and `-Infinity` are allowed,
even though they are illegal according to the JSON specification.
:param as_string: If `True`, serialize to a string instead of a Python
`decimal.Decimal` type.
:param kwargs: The same keyword arguments that :class:`Number` receives.
.. versionadded:: 1.2.0