Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SimpleDecimalField #7

Open
math-a3k opened this issue Jan 30, 2021 · 0 comments
Open

Implement SimpleDecimalField #7

math-a3k opened this issue Jan 30, 2021 · 0 comments

Comments

@math-a3k
Copy link
Owner

Django's DecimalField may be confusing for data inputters. It validates decimal places and digits before min and max values (added as separate validators) and the error may be confusing for users.

It would be better to have a field that converts the input to Decimal and then checks whether it is betwen max and min values, truncating the exceeding precision.

I.e, DecimalField(max_digits=5, decimal_places=3) has an implicit max value of 99.999 and min of -99.999. If validators=[MinValueValidator(2.0), MaxValueValidator(8.0)], the values 104.5, 80.3444, 2.1234, -999 would rise a "check the digits" or "invalid value" errors.

Taking into account the DRF implementation of DecimalField, it would be simpler and better if the field quantizes the input to the desired precision and checks if it is between max and min. Then for 104.5 it would say "value larger than max", 80.3444: "value larger than max", for 2.1234 it would store 2.123 (selecting rounding), and for -999 would say "value smaller than min".

This may require adjust the field mapping of DRF (check).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant