Ticket #7726: patch.diff

File patch.diff, 2.8 KB (added by elbarto, 14 years ago)

I've send a new patch with tests which returns 'OK' with invalid_models test.

  • django/core/management/validation.py

     
    6767                        e.add(opts,  mdigits_msg % f.name)
    6868                except (ValueError, TypeError):
    6969                    e.add(opts, mdigits_msg % f.name)
     70                improperly_configured_msg = '"%s": DecimalFields require a "max_digits" attribute that is higher than "decimal_places" attribute.'
     71                try:
     72                    max_digits = int(f.max_digits)
     73                    decimal_places = int(f.decimal_places)
     74                    if (max_digits > 0) and (decimal_places >=0):
     75                        if not (max_digits > decimal_places):
     76                            e.add(opts, improperly_configured_msg % f.name)
     77                except (ValueError, TypeError):
     78                    pass
    7079            if isinstance(f, models.FileField) and not f.upload_to:
    7180                e.add(opts, '"%s": FileFields require an "upload_to" attribute.' % f.name)
    7281            if isinstance(f, models.ImageField):
  • tests/modeltests/invalid_models/models.py

     
    1414    decimalfield = models.DecimalField()
    1515    decimalfield2 = models.DecimalField(max_digits=-1, decimal_places=-1)
    1616    decimalfield3 = models.DecimalField(max_digits="bad", decimal_places="bad")
     17    decimalfield4 = models.DecimalField(max_digits=9, decimal_places=10)
     18    decimalfield5 = models.DecimalField(max_digits=10, decimal_places=10)
    1719    filefield = models.FileField()
    1820    choices = models.CharField(max_length=10, choices='bad')
    1921    choices2 = models.CharField(max_length=10, choices=[(1,2,3),(1,2,3)])
     
    241243invalid_models.fielderrors: "decimalfield2": DecimalFields require a "max_digits" attribute that is a positive integer.
    242244invalid_models.fielderrors: "decimalfield3": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
    243245invalid_models.fielderrors: "decimalfield3": DecimalFields require a "max_digits" attribute that is a positive integer.
     246invalid_models.fielderrors: "decimalfield4": DecimalFields require a "max_digits" attribute that is higher than "decimal_places" attribute.
     247invalid_models.fielderrors: "decimalfield5": DecimalFields require a "max_digits" attribute that is higher than "decimal_places" attribute.
    244248invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.
    245249invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list).
    246250invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples.
Back to Top