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,)
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)