--- /dev/null
+from django.db import models
+from django.conf import settings
+
+class Album(models.Model):
+ name = models.CharField(max_length=120)
+ caption = models.TextField(blank=True, null=True)
+ slug = models.SlugField()
+
+ def get_main_image(self):
+ main_photo = Photo.objects.filter(album=self).order_by('order','image')[0]
+ return main_photo.image
+
+ def __unicode__(self):
+ return "%s" %(self.name,)
+
+def get_upload_path(photo, filename):
+ if photo.album:
+ return "photos/%s/%s" %(photo.album.slug, filename)
+ else:
+ return "photos/%s" %(filename)
+
+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')
+
+ def __unicode__(self):
+ return "%s" %(self.image)