Proper handling of empty images and missing fields

Fixes #42
This commit is contained in:
Matthew Tretter 2011-11-03 12:31:04 -04:00
parent bbc0bffd88
commit 3022eb037d
2 changed files with 8 additions and 6 deletions

View file

@ -21,9 +21,9 @@ class AdminThumbnail(object):
self.template = template
def __call__(self, obj):
thumbnail = getattr(obj, self.image_field, None)
if not thumbnail:
try:
thumbnail = getattr(obj, self.image_field)
except AttributeError:
raise Exception('The property %s is not defined on %s.' % \
(self.image_field, obj.__class__.__name__))

View file

@ -1,3 +1,5 @@
<a href="{{ model.get_absolute_url|default:original_image.url }}">
<img src="{{ thumbnail.url }}">
</a>
{% if thumbnail %}
<a href="{{ model.get_absolute_url|default:original_image.url }}">
<img src="{{ thumbnail.url }}">
</a>
{% endif %}