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):
10 main_photo = Photo.objects.filter(album=self).order_by('order','image')[0]
11 return main_photo.image
13 def __unicode__(self):
14 return "%s" %(self.name,)
16 def get_upload_path(photo, filename):
18 return "photos/%s/%s" %(photo.album.slug, filename)
20 return "photos/%s" %(filename)
22 class Photo(models.Model):
23 image = models.ImageField(upload_to=get_upload_path, null=True)
24 caption = models.TextField(blank=True, null=True)
25 order = models.IntegerField(blank=True, null=True)
26 album = models.ForeignKey('Album')
28 def __unicode__(self):
29 return "%s" %(self.image)