]> git.sommitrealweird.co.uk Git - sommitrealweird.git/blob - sommitrealweird/photo/models.py
Checky little photo import script
[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         main_photo = Photo.objects.filter(album=self).order_by('order','image')[0]
11         return main_photo.image
12
13     def __unicode__(self):
14         return "%s" %(self.name,)
15
16 def get_upload_path(photo, filename):
17     if photo.album:
18         return "photos/%s/%s" %(photo.album.slug, filename)
19     else:
20         return "photos/%s" %(filename)
21
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')
27
28     def __unicode__(self):
29         return "%s" %(self.image)