]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/photo/models.py
title fix for blog
[sommitrealweird.git] / sommitrealweird / photo / models.py
1 from django.db import models
2 from django.conf import settings
3
4 class Album(models.Model):
5     name = models.CharField(max_length=120)
6     caption = models.TextField(blank=True, null=True)
7     slug = models.SlugField()
8
9     def get_main_image(self):
10         try:
11             main_photo = Photo.objects.filter(album=self).order_by('order','image')[0]
12             return main_photo.image
13         except:
14             return None
15
16     def __unicode__(self):
17         return "%s" %(self.name,)
18
19 def get_upload_path(photo, filename):
20     if photo.album:
21         return "photos/%s/%s" %(photo.album.slug, filename)
22     else:
23         return "photos/%s" %(filename)
24
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')
30
31     def __unicode__(self):
32         return "%s" %(self.image)