1 from django.db import models
2 from django.conf import settings
4 class Album(models.Model):
5 name = models.CharField(max_length=120)
6 caption = models.TextField(blank=True, null=True)
7 slug = models.SlugField()
9 def get_main_image(self):
11 main_photo = Photo.objects.filter(album=self).order_by('order','image')[0]
12 return main_photo.image
16 def __unicode__(self):
17 return "%s" %(self.name,)
19 def get_upload_path(photo, filename):
21 return "photos/%s/%s" %(photo.album.slug, filename)
23 return "photos/%s" %(filename)
25 class Photo(models.Model):
26 image = models.ImageField(upload_to=get_upload_path, null=True)
27 caption = models.TextField(blank=True, null=True)
28 order = models.IntegerField(blank=True, null=True)
29 album = models.ForeignKey('Album', on_delete=models.CASCADE)
31 def __unicode__(self):
32 return "%s" %(self.image)