Skip to content

Commit

Permalink
Fix #16570: Restore ability to have decimal fields where max_digits e…
Browse files Browse the repository at this point in the history
…quals decimal_places. Thanks dcwatson and kenth.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17089 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
kmtracey committed Nov 12, 2011
1 parent 63ba472 commit efe4e2e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion AUTHORS
Expand Up @@ -528,7 +528,7 @@ answer newbie questions, and generally made Django that much better:
wam-djangobug@wamber.net wam-djangobug@wamber.net
Wang Chun <wangchun@exoweb.net> Wang Chun <wangchun@exoweb.net>
Filip Wasilewski <filip.wasilewski@gmail.com> Filip Wasilewski <filip.wasilewski@gmail.com>
Dan Watson <http://theidioteque.net/> Dan Watson <http://danwatson.net/>
Joel Watts <joel@joelwatts.com> Joel Watts <joel@joelwatts.com>
Lakin Wecker <lakin@structuredabstraction.com> Lakin Wecker <lakin@structuredabstraction.com>
Chris Wesseling <Chris.Wesseling@cwi.nl> Chris Wesseling <Chris.Wesseling@cwi.nl>
Expand Down
4 changes: 2 additions & 2 deletions django/core/management/validation.py
Expand Up @@ -72,9 +72,9 @@ def get_validation_errors(outfile, app=None):
mdigits_ok = True mdigits_ok = True
except (ValueError, TypeError): except (ValueError, TypeError):
e.add(opts, mdigits_msg % f.name) 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 decimalp_ok and mdigits_ok:
if decimal_places >= max_digits: if decimal_places > max_digits:
e.add(opts, invalid_values_msg % f.name) e.add(opts, invalid_values_msg % f.name)
if isinstance(f, models.FileField) and not f.upload_to: if isinstance(f, models.FileField) and not f.upload_to:
e.add(opts, '"%s": FileFields require an "upload_to" attribute.' % f.name) e.add(opts, '"%s": FileFields require an "upload_to" attribute.' % f.name)
Expand Down
2 changes: 1 addition & 1 deletion docs/ref/models/fields.txt
Expand Up @@ -450,7 +450,7 @@ A fixed-precision decimal number, represented in Python by a
.. attribute:: DecimalField.max_digits .. attribute:: DecimalField.max_digits


The maximum number of digits allowed in the number. Note that this number 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 .. attribute:: DecimalField.decimal_places


Expand Down
3 changes: 1 addition & 2 deletions tests/modeltests/invalid_models/invalid_models/models.py
Expand Up @@ -243,8 +243,7 @@ class PrimaryKeyNull(models.Model):
invalid_models.fielderrors: "decimalfield2": DecimalFields require a "max_digits" attribute that is a positive integer. 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 "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: "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: "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: "decimalfield5": DecimalFields require a "max_digits" attribute value that is greater than the value of the "decimal_places" attribute.
invalid_models.fielderrors: "filefield": FileFields require an "upload_to" 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: "choices": "choices" should be iterable (e.g., a tuple or list).
invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples. invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples.
Expand Down
5 changes: 5 additions & 0 deletions tests/regressiontests/model_fields/models.py
Expand Up @@ -69,6 +69,11 @@ class BooleanModel(models.Model):
class RenamedField(models.Model): class RenamedField(models.Model):
modelname = models.IntegerField(name="fieldname", choices=((1,'One'),)) 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 # FileField


Expand Down

0 comments on commit efe4e2e

Please sign in to comment.