X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/blobdiff_plain/d82db041f520a51eccee6788ebc3a494e2a4280f..HEAD:/sommitrealweird/photo/models.py diff --git a/sommitrealweird/photo/models.py b/sommitrealweird/photo/models.py index 1e2cc68..31751c3 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,) @@ -23,7 +26,7 @@ class Photo(models.Model): image = models.ImageField(upload_to=get_upload_path, null=True) caption = models.TextField(blank=True, null=True) order = models.IntegerField(blank=True, null=True) - album = models.ForeignKey('Album') + album = models.ForeignKey('Album', on_delete=models.CASCADE) def __unicode__(self): return "%s" %(self.image)