【发布时间】:2011-02-10 06:45:57
【问题描述】:
class Product(models.Model):
...
image = models.ImageField(upload_to = generate_filename, blank = True)
当我使用 ImageField (blank=True) 并且不选择图像进入管理表单时,会发生异常。
在 django 代码中你可以看到:
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 有关于这个问题的票 #13327,但似乎不能很快解决。如何使这些字段可选?
【问题讨论】:
-
你找到解决办法了吗,看来我现在也有同样的问题
标签: django django-models