When I do the following inside an admin file:
photo = Photo.objects.get(original_image__exact=file_name)
val = photo.admin_thumbnail.url
I get this error:
Caught DoesNotExist while rendering: Photo matching query does not exist.
Here is my class:
class AdminImageWidget(forms.FileInput):
"""
A ImageField Widget for admin that shows a thumbnail.
"""
def __init__(self, attrs={}, *args, **kwargs):
super(AdminImageWidget, self).__init__(attrs)
def render(self, name, value, attrs=None):
output = []
file_name = unicode(value)
if file_name:
photo = Photo.objects.get(original_image__exact=file_name)
val = photo.admin_thumbnail.url
output.append(('<a target="_BLANK" href="%s">'
'<img src="%s" /></a> '
% (val, val)))
output.append(super(AdminImageWidget, self).render(name, value, attrs))
return mark_safe(u''.join(output))
However, if I do it in the shell (python manage.py shell), it works perfectly!
weird huh?