I'm having a silly issue with the admin interface and an ImageField in
one of my models. A simple model I have contains an ImageField, and
many objects of this model are related to some other model (Project,
not shown). I can add/view images just fine, but when I try to delete
an image, I get a value error saying:
"ValueError at /admin/projects/project/1/
The 'image' attribute has no file associated with it."
The entry correctly deletes from my DB (on successive loads of the
admin page, I no longer see the entry), the file does not delete from
my directory however, and this error pops up. Any thoughts on why?
I have tried with & without my custom delete function, with the same
results. Help would be appreciated, thanks.
Ryan
# ProjectImage Model
def get_project_image_path(instance, filename):
return os.path.join('projects', instance.project.name_slug,
filename)
class ProjectImage(models.Model):
project = models.ForeignKey(Project, verbose_name='project',
help_text='The project that this image is related to.')
image = models.ImageField(upload_to=get_project_image_path)
description = models.CharField(max_length=128, help_text='The image
description is a small text blurb used to help readers identify what
they\'re looking at when viewing an image.', blank=True)
class Meta:
verbose_name='project image'
verbose_name_plural='project images'
def __unicode__(self):
return self.image.path
def delete(self):
default_storage.delete(self.image.path)
super(ProjectImage, self).delete()
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
django...@googlegroups.com.
To unsubscribe from this group, send email to
django-users...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.