Decimal field¶
Field for decimal numbers
This code save to MongoDB document:
-
class
yadm.fields.decimal.
DecimalField
(*, context=None, **kwargs)¶ Field for work with
decimal.Decimal
.Parameters: - context (decimal.Context) – context for decimal operations
(default: run
decimal.getcontext()
when need) - default (decimal.Decimal) –
TODO: context in copy()
-
context
¶ Context.
Returns: decimal.Context
for values
-
from_mongo
(document, value)¶ Convert mongo value to python value.
Parameters: - document (BaseDocument) – document
- value – mongo value
Returns: python value
-
get_fake
(document, faker, depth)¶ Return fake data for testing.
-
prepare_value
(document, value)¶ Cast value to
decimal.Decimal
.
-
to_mongo
(document, value)¶ Convert python value to mongo value.
Parameters: - document (BaseDocument) – document
- value – python value
Returns: mongo value
- context (decimal.Context) – context for decimal operations
(default: run