Ticket #8918: file.patch

File file.patch, 4.1 KB (added by dc, 16 years ago)

Makes upload_to optional

  • django/core/management/validation.py

     
    4444                    e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute.' % f.name)
    4545                if f.max_digits is None:
    4646                    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)
    4947            if isinstance(f, models.ImageField):
    5048                try:
    5149                    from PIL import Image
  • tests/modeltests/invalid_models/models.py

     
    185185model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute.
    186186invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute.
    187187invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute.
    188 invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.
    189188invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list).
    190189invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples.
    191190invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples.
  • tests/modeltests/files/models.py

     
    3333    custom = models.FileField(storage=temp_storage, upload_to=custom_upload_to)
    3434    random = models.FileField(storage=temp_storage, upload_to=random_upload_to)
    3535    default = models.FileField(storage=temp_storage, upload_to='tests', default='tests/default.txt')
     36    empty = models.FileField(storage=temp_storage, upload_to='')
    3637
    3738__test__ = {'API_TESTS':"""
    3839# Attempting to access a FileField from the class raises a descriptive error
     
    134135>>> obj4.random
    135136<FieldFile: .../random_file>
    136137
     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
    137145# Clean up the temporary files and dir.
    138146>>> obj1.normal.delete()
    139147>>> obj2.normal.delete()
    140148>>> obj3.default.delete()
    141149>>> obj4.random.delete()
     150>>> obj5.empty.delete()
    142151>>> shutil.rmtree(temp_storage_location)
    143152"""}
  • docs/ref/models/fields.txt

     
    438438``FileField``
    439439-------------
    440440
    441 .. class:: FileField(upload_to=None, [max_length=100, **options])
     441.. class:: FileField([upload_to='', max_length=100, **options])
    442442
    443443A file-upload field.
    444444
     
    446446    The ``primary_key`` and ``unique`` arguments are not supported, and will
    447447    raise a ``TypeError`` if used.
    448448
    449 Has one **required** argument:
     449Has two optional arguments:
    450450
    451451.. attribute:: FileField.upload_to
    452452
     
    484484                                when determining the final destination path.
    485485        ======================  ===============================================
    486486
    487 Also has one optional argument:
     487    .. versionchanged:: 1.1
    488488
     489    :attr:`~FileField.upload_to` is optional and empty by default.
     490
    489491.. attribute:: FileField.storage
    490492
    491493    .. versionadded:: 1.0
     
    603605``ImageField``
    604606--------------
    605607
    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])
    607609
    608610Like :class:`FileField`, but validates that the uploaded object is a valid
    609611image. Has two extra optional arguments:
Back to Top