Ticket #12404: 12404_new.diff
File 12404_new.diff, 2.9 KB (added by , 15 years ago) |
---|
-
django/core/management/validation.py
37 37 e.add(opts, '"%s": You can\'t use "id" as a field name, because each model automatically gets an "id" field if none of the fields have primary_key=True. You need to either remove/rename your "id" field or add primary_key=True to a field.' % f.name) 38 38 if f.name.endswith('_'): 39 39 e.add(opts, '"%s": Field names cannot end with underscores, because this would lead to ambiguous queryset filters.' % f.name) 40 if isinstance(f, models.CharField) and f.max_length in (None, 0): 41 e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name) 40 if isinstance(f, models.CharField): 41 try: 42 max_length = int(f.max_length) 43 if max_length <= 0: 44 e.add(opts, '"%s": CharFields require a "max_length attribute greater than zero."' % f.name) 45 except ValueError: 46 e.add(opts, '"%s": CharFields require a "max_length" attribute of type int.' % f.name) 47 except TypeError: 48 if f.max_length is None: 49 e.add(opts, '"%s": CharFields require a "max_length" attribute.' % f.name) 50 else: 51 e.add(opts, '"%s": CharFields require a "max_length" attribute of type int.' % f.name) 52 42 53 if isinstance(f, models.DecimalField): 43 54 if f.decimal_places is None: 44 55 e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name) -
tests/modeltests/invalid_models/models.py
8 8 9 9 class FieldErrors(models.Model): 10 10 charfield = models.CharField() 11 badmax = models.CharField(max_length="cheese") 12 badtype = models.CharField(max_length=type) 11 13 decimalfield = models.DecimalField() 12 14 filefield = models.FileField() 13 15 choices = models.CharField(max_length=10, choices='bad') … … 184 186 185 187 186 188 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute. 189 invalid_models.fielderrors: "badmax": CharFields require a "max_length" attribute of type int. 190 invalid_models.fielderrors: "badtype": CharFields require a "max_length" attribute of type int. 187 191 invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute. 188 192 invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute. 189 193 invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.