What is meant with validation for django imagefield?

The ImageField docu states:

Inherits all attributes and methods from FileField, but also validates that the uploaded object is a valid image.

Yet any string is accepted

class Foo(Model):
    pic = models.ImageField(upload_to='files')

e.g. I can save this without error and nothing is uploaded to files (not even with a correct file)

fooinstance.pic="bogus"
fooinstance.save()
fooinstance.pic.__dict__
{'_file': None,
 'name': 'bogus',
 'instance': <Foo:...>,
 'field': <django.db.models.fields.files.ImageField: pic>,
 'storage': <django.core.files.storage.filesystem.FileSystemStorage at 0x721add4903d0>,
 '_committed': True}

Meanwhile the FileField works/uploads perfectly fine

the uploaded object (eg. when used in a form).

You're just assigning a string (path-in-storage) to the field, and not even calling full_clean on the model.

Вернуться на верх