views:

82

answers:

1
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?

A: 

Set null=True (see documentation)

class Product(models.Model):
    ...    
    image = models.ImageField(upload_to = generate_filename, blank = True, null=True)
Nathan
null=True is scary, blank=True is enough because ImageField/FileField are actually CharFields underneath...
xyld