DecimalField with no max_digits and decimal_places

151 views
Skip to first unread message

Shai Berger

unread,
Jun 20, 2015, 5:40:23 PM6/20/15
to django-d...@googlegroups.com
Hi,

Django's DecimalField requires both max_digits and decimal_places. Database
backends allow them to be dropped, to specify an "unlimited precision" field.
Adding support for this in Django is probably not very helpful for new apps,
but can help significantly in using Django against legacy databases. I have
opened ticket #24920[1] to track this feature.

I'm raising it here (at Tim's kind suggestion) because there's a bit of a
design decision to be made about implementing it: Supporting it in the
existing DecimalField class would lead to quite ugly code with repeated
branching on whether the attributes have values or not. It would be
significantly nicer to do this in a new field type. But that discrepancy between
field type and database type would probably be a less-than-optimal public API.

What do you think?

Shai.


[1] https://code.djangoproject.com/ticket/24920

Aymeric Augustin

unread,
Jun 21, 2015, 5:17:25 AM6/21/15
to django-d...@googlegroups.com
“Unlimited” precision is a natural semantic DecimalField(). Likewise, if we
ever make max_length optional in CharField(), now providing it will mean
“unlimited” length. (Scare quotes because storage is never really unlimited.)

I think we should provide the best API for our users and deal with the code.
I’m in favor of not introducing another class and figuring out the least awful
way to arrange the code paths in DecimalField.

--
Aymeric.

Claude Paroz

unread,
Jun 21, 2015, 2:02:44 PM6/21/15
to django-d...@googlegroups.com
On Sunday, June 21, 2015 at 11:17:25 AM UTC+2, Aymeric Augustin wrote:
(...)

I think we should provide the best API for our users and deal with the code.
I’m in favor of not introducing another class and figuring out the least awful
way to arrange the code paths in DecimalField.

+1

Claude
Reply all
Reply to author
Forward
0 new messages