Django - how to make ImageField/FileField optional?

Posted by ilya on Stack Overflow See other posts from Stack Overflow or by ilya
Published on 2010-04-20T18:30:43Z Indexed on 2010/04/20 18:33 UTC
Read the original article Hit count: 206

Filed under:
|
class Product(models.Model):
    ...    
    image = models.ImageField(upload_to = generate_filename, blank = True)  

When I use ImageField (blank=True) and do not select image into admin form, exception occures.

In django code you can see this:

class FieldFile(File):
   ....

    def _require_file(self):
        if not self:
            raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)

    def _get_file(self):
        self._require_file()
        ...

Django trac has ticket #13327 about this problem, but seems it can't be fixed soon. How to make these field optional?

© Stack Overflow or respective owner

Related posts about django-models

Related posts about django