X-Git-Url: https://git.sommitrealweird.co.uk/sommitrealweird.git/blobdiff_plain/1487722766c9e649c95a6f25ae29b0680bdc1be0..d82db041f520a51eccee6788ebc3a494e2a4280f:/sommitrealweird/photo/models.py diff --git a/sommitrealweird/photo/models.py b/sommitrealweird/photo/models.py new file mode 100644 index 0000000..1e2cc68 --- /dev/null +++ b/sommitrealweird/photo/models.py @@ -0,0 +1,29 @@ +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)