'Validates that the input is a decimal number. Returns a Decimal
instance. Returns None for empty values. Ensures that there are no more
than max_digits in the number, and no more than decimal_places digits
after the decimal point.'

def to_python(self, value):

    if (value in validators.EMPTY_VALUES):
        return None
    if self.localize:
        value = formats.sanitize_separators(value)
    value = smart_str(value).strip()
    try:
        value = Decimal(value)
    except DecimalException:
        raise ValidationError(self.error_messages['invalid'])
    return value
