slug = models.SlugField()
def get_main_image(self):
- main_photo = Photo.objects.filter(album=self).order_by('order','image')[0]
- return main_photo.image
+ try:
+ main_photo = Photo.objects.filter(album=self).order_by('order','image')[0]
+ return main_photo.image
+ except:
+ return None
def __unicode__(self):
return "%s" %(self.name,)
{% if object_list %}
{% for album in object_list %}
<div class="album">
+ {% if album.get_main_image %}
<a href="{{ album.slug }}/"><img src="{{ album.get_main_image.url|thumbnail:"width=250" }}" alt="{{ album.get_main_image.caption }}" /></a>
+ {% endif %}
<h2><a href="{{ album.slug }}/">{{ album.name }}</a></h2>
<p>{{ album.caption }}</h2>
</div>