class documentation

class DecimalField(Field): (source)

View In Hierarchy

Undocumented

Method __init__ Undocumented
Method quantize Quantize the decimal value to the configured precision.
Method to_internal_value Validate that the input is a decimal number and return a Decimal instance.
Method to_representation Transform the *outgoing* native value into primitive data.
Method validate_empty_values Validate empty values, and either:
Method validate_precision Ensure that there are no more than max_digits in the number, and no more than decimal_places digits after the decimal point.
Constant MAX_STRING_LENGTH Undocumented
Class Variable default_error_messages Undocumented
Instance Variable coerce_to_string Undocumented
Instance Variable decimal_places Undocumented
Instance Variable localize Undocumented
Instance Variable max_digits Undocumented
Instance Variable max_value Undocumented
Instance Variable max_whole_digits Undocumented
Instance Variable min_value Undocumented
Instance Variable rounding Undocumented

Inherited from Field:

Method __deepcopy__ When cloning fields we instantiate using the arguments it was originally created with, rather than copying the complete state.
Method __new__ When a field is instantiated, we store the arguments that were used, so that we can present a helpful representation of the object.
Method __repr__ Fields are represented using their initial calling arguments. This allows us to create descriptive representations for serializer instances that show all the declared fields on the serializer.
Method bind Initializes the field name and parent for the field instance. Called when a field is added to the parent serializer instance.
Method fail A helper method that simply raises a validation error.
Method get_attribute Given the *outgoing* object instance, return the primitive value that should be used for this field.
Method get_default Return the default value to use when validating data if no input is provided for this field.
Method get_initial Return a value to use when the field is being returned as a primitive value, without any object instance.
Method get_validators Undocumented
Method get_value Given the *incoming* primitive data, return the value for this field that should be validated and transformed to a native value.
Method run_validation Validate a simple representation and return the internal value.
Method run_validators Test the given value against all the validators on the field, and either raise a `ValidationError` or simply return.
Method validators.setter Undocumented
Class Variable default_validators Undocumented
Instance Variable allow_null Undocumented
Instance Variable default Undocumented
Instance Variable default_empty_html Undocumented
Instance Variable error_messages Undocumented
Instance Variable field_name Undocumented
Instance Variable help_text Undocumented
Instance Variable initial Undocumented
Instance Variable label Undocumented
Instance Variable parent Undocumented
Instance Variable read_only Undocumented
Instance Variable required Undocumented
Instance Variable source Undocumented
Instance Variable source_attrs Undocumented
Instance Variable style Undocumented
Instance Variable write_only Undocumented
Property context Returns the context as passed to the root serializer on initialization.
Property root Returns the top-level serializer for this field.
Property validators Undocumented
Instance Variable _creation_counter Undocumented
Instance Variable _validators Undocumented
def __init__(self, max_digits, decimal_places, coerce_to_string=None, max_value=None, min_value=None, localize=False, rounding=None, **kwargs): (source)

Undocumented

def quantize(self, value): (source)

Quantize the decimal value to the configured precision.

def to_internal_value(self, data): (source)

Validate that the input is a decimal number and return a Decimal instance.

def to_representation(self, value): (source)

Transform the *outgoing* native value into primitive data.

def validate_empty_values(self, data): (source)

Validate empty values, and either: * Raise `ValidationError`, indicating invalid data. * Raise `SkipField`, indicating that the field should be ignored. * Return (True, data), indicating an empty value that should be returned without any further validation being applied. * Return (False, data), indicating a non-empty value, that should have validation applied as normal.

def validate_precision(self, value): (source)

Ensure that there are no more than max_digits in the number, and no more than decimal_places digits after the decimal point. Override this method to disable the precision validation for input values or to enhance it in any way you need to.

MAX_STRING_LENGTH: int = (source)

Undocumented

Value
1000
default_error_messages = (source)
coerce_to_string: bool = (source)

Undocumented

decimal_places = (source)

Undocumented

localize = (source)

Undocumented

max_digits = (source)

Undocumented

max_value = (source)

Undocumented

max_whole_digits = (source)

Undocumented

min_value = (source)

Undocumented

rounding = (source)

Undocumented