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
This commit is contained in:
Karen Tracey 2011-11-12 19:53:56 +00:00
parent 63ba472cc4
commit efe4e2e517
5 changed files with 10 additions and 6 deletions

View File

@ -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>

View File

@ -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)

View File

@ -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

View File

@ -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: "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.

View File

@ -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