From 6746b20632b76e4a04be07428ab2581483869d40 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Sun, 29 Mar 2009 14:56:45 +0100 Subject: [PATCH] Photo album improvements --- sommitrealweird/photo/models.py | 7 +++++-- sommitrealweird/photo/templates/photo/album_index.html | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sommitrealweird/photo/models.py b/sommitrealweird/photo/models.py index 1e2cc68..3a5d123 100644 --- a/sommitrealweird/photo/models.py +++ b/sommitrealweird/photo/models.py @@ -7,8 +7,11 @@ class Album(models.Model): 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,) diff --git a/sommitrealweird/photo/templates/photo/album_index.html b/sommitrealweird/photo/templates/photo/album_index.html index edfbc9f..402deed 100644 --- a/sommitrealweird/photo/templates/photo/album_index.html +++ b/sommitrealweird/photo/templates/photo/album_index.html @@ -6,7 +6,9 @@ {% if object_list %} {% for album in object_list %}
+ {% if album.get_main_image %} {{ album.get_main_image.caption }} + {% endif %}

{{ album.name }}

{{ album.caption }}

-- 2.30.2