Ticket #8918: file.patch
File file.patch, 4.1 KB (added by , 16 years ago) |
---|
-
django/core/management/validation.py
44 44 e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name) 45 45 if f.max_digits is None: 46 46 e.add(opts, '"%s": DecimalFields require a "max_digits" attribute.' % f.name) 47 if isinstance(f, models.FileField) and not f.upload_to:48 e.add(opts, '"%s": FileFields require an "upload_to" attribute.' % f.name)49 47 if isinstance(f, models.ImageField): 50 48 try: 51 49 from PIL import Image -
tests/modeltests/invalid_models/models.py
185 185 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute. 186 186 invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute. 187 187 invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute. 188 invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.189 188 invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list). 190 189 invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples. 191 190 invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples. -
tests/modeltests/files/models.py
33 33 custom = models.FileField(storage=temp_storage, upload_to=custom_upload_to) 34 34 random = models.FileField(storage=temp_storage, upload_to=random_upload_to) 35 35 default = models.FileField(storage=temp_storage, upload_to='tests', default='tests/default.txt') 36 empty = models.FileField(storage=temp_storage, upload_to='') 36 37 37 38 __test__ = {'API_TESTS':""" 38 39 # Attempting to access a FileField from the class raises a descriptive error … … 134 135 >>> obj4.random 135 136 <FieldFile: .../random_file> 136 137 138 # upload_to can be empty 139 140 >>> obj5 = Storage() 141 >>> obj5.empty.save('django_test.txt', ContentFile('more content')) 142 >>> obj5.empty 143 <FieldFile: ./django_test.txt> 144 137 145 # Clean up the temporary files and dir. 138 146 >>> obj1.normal.delete() 139 147 >>> obj2.normal.delete() 140 148 >>> obj3.default.delete() 141 149 >>> obj4.random.delete() 150 >>> obj5.empty.delete() 142 151 >>> shutil.rmtree(temp_storage_location) 143 152 """} -
docs/ref/models/fields.txt
438 438 ``FileField`` 439 439 ------------- 440 440 441 .. class:: FileField( upload_to=None, [max_length=100, **options])441 .. class:: FileField([upload_to='', max_length=100, **options]) 442 442 443 443 A file-upload field. 444 444 … … 446 446 The ``primary_key`` and ``unique`` arguments are not supported, and will 447 447 raise a ``TypeError`` if used. 448 448 449 Has one **required** argument:449 Has two optional arguments: 450 450 451 451 .. attribute:: FileField.upload_to 452 452 … … 484 484 when determining the final destination path. 485 485 ====================== =============================================== 486 486 487 Also has one optional argument: 487 .. versionchanged:: 1.1 488 488 489 :attr:`~FileField.upload_to` is optional and empty by default. 490 489 491 .. attribute:: FileField.storage 490 492 491 493 .. versionadded:: 1.0 … … 603 605 ``ImageField`` 604 606 -------------- 605 607 606 .. class:: ImageField( upload_to=None, [height_field=None, width_field=None, max_length=100, **options])608 .. class:: ImageField([upload_to='', height_field=None, width_field=None, max_length=100, **options]) 607 609 608 610 Like :class:`FileField`, but validates that the uploaded object is a valid 609 611 image. Has two extra optional arguments: