Photo album improvements
authorBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 29 Mar 2009 13:56:45 +0000 (14:56 +0100)
committerBrett Parker <iDunno@sommitrealweird.co.uk>
Sun, 29 Mar 2009 13:56:45 +0000 (14:56 +0100)
sommitrealweird/photo/models.py
sommitrealweird/photo/templates/photo/album_index.html

index 1e2cc6842da83f4c41f3311d7f761dc1f0257209..3a5d123c8e5b134de54185093c7df7e92c28a5fd 100644 (file)
@@ -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,)
index edfbc9ff3f58f1e92b03a616e0fe010a25034964..402deedfc0ab4d246474ec49b2b218f91a0965f1 100644 (file)
@@ -6,7 +6,9 @@
     {% 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>