From efe4e2e5178d2d6e6f710c3edee0d07cd6a60ab5 Mon Sep 17 00:00:00 2001 From: Karen Tracey Date: Sat, 12 Nov 2011 19:53:56 +0000 Subject: [PATCH] Fix #16570: Restore ability to have decimal fields where max_digits equals decimal_places. Thanks dcwatson and kenth. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17089 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 2 +- django/core/management/validation.py | 4 ++-- docs/ref/models/fields.txt | 2 +- tests/modeltests/invalid_models/invalid_models/models.py | 3 +-- tests/regressiontests/model_fields/models.py | 5 +++++ 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index 8224cda639..5889065fef 100644 --- a/AUTHORS +++ b/AUTHORS @@ -528,7 +528,7 @@ answer newbie questions, and generally made Django that much better: wam-djangobug@wamber.net Wang Chun Filip Wasilewski - Dan Watson + Dan Watson Joel Watts Lakin Wecker Chris Wesseling diff --git a/django/core/management/validation.py b/django/core/management/validation.py index 3cb2e345e8..3aaeaa94c8 100644 --- a/django/core/management/validation.py +++ b/django/core/management/validation.py @@ -72,9 +72,9 @@ def get_validation_errors(outfile, app=None): mdigits_ok = True except (ValueError, TypeError): e.add(opts, mdigits_msg % f.name) - invalid_values_msg = '"%s": DecimalFields require a "max_digits" attribute value that is greater than the value of the "decimal_places" attribute.' + invalid_values_msg = '"%s": DecimalFields require a "max_digits" attribute value that is greater than or equal to the value of the "decimal_places" attribute.' if decimalp_ok and mdigits_ok: - if decimal_places >= max_digits: + if decimal_places > max_digits: e.add(opts, invalid_values_msg % f.name) if isinstance(f, models.FileField) and not f.upload_to: e.add(opts, '"%s": FileFields require an "upload_to" attribute.' % f.name) diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index a5d66f8dcf..e0cf92f9c3 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -450,7 +450,7 @@ A fixed-precision decimal number, represented in Python by a .. attribute:: DecimalField.max_digits The maximum number of digits allowed in the number. Note that this number - must be greater than ``decimal_places``, if it exists. + must be greater than or equal to ``decimal_places``, if it exists. .. attribute:: DecimalField.decimal_places diff --git a/tests/modeltests/invalid_models/invalid_models/models.py b/tests/modeltests/invalid_models/invalid_models/models.py index 422d70f21b..93c1c66f1c 100644 --- a/tests/modeltests/invalid_models/invalid_models/models.py +++ b/tests/modeltests/invalid_models/invalid_models/models.py @@ -243,8 +243,7 @@ invalid_models.fielderrors: "decimalfield2": DecimalFields require a "decimal_pl invalid_models.fielderrors: "decimalfield2": DecimalFields require a "max_digits" attribute that is a positive integer. invalid_models.fielderrors: "decimalfield3": DecimalFields require a "decimal_places" attribute that is a non-negative integer. invalid_models.fielderrors: "decimalfield3": DecimalFields require a "max_digits" attribute that is a positive integer. -invalid_models.fielderrors: "decimalfield4": DecimalFields require a "max_digits" attribute value that is greater than the value of the "decimal_places" attribute. -invalid_models.fielderrors: "decimalfield5": DecimalFields require a "max_digits" attribute value that is greater than the value of the "decimal_places" attribute. +invalid_models.fielderrors: "decimalfield4": DecimalFields require a "max_digits" attribute value that is greater than or equal to the value of the "decimal_places" attribute. invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute. invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list). invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples. diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py index 8adf7b655b..4dcfb17bb3 100644 --- a/tests/regressiontests/model_fields/models.py +++ b/tests/regressiontests/model_fields/models.py @@ -69,6 +69,11 @@ class BooleanModel(models.Model): class RenamedField(models.Model): modelname = models.IntegerField(name="fieldname", choices=((1,'One'),)) +# This model isn't used in any test, just here to ensure it validates successfully. +# See ticket #16570. +class DecimalLessThanOne(models.Model): + d = models.DecimalField(max_digits=3, decimal_places=3) + ############################################################################### # FileField