Image model to use with thumbnailer

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Image(models.Model):
title = models.CharField('Title', max_length="30")
image = models.ImageField(upload_to='foto')
def __unicode__(self):
return self.title
@models.permalink
def get_absolute_url(self):
return 'foto.views.object_detail', (), {'object_id': self.pk}
@property
def image_file(self):
return "%s%s" % (settings.MEDIA_ROOT, self.image)
@property
def thumb_file(self):
path, name = self.image_file.rsplit('/', 1)
return ''.join((path, '/tn_', name))
@property
def thumb(self):
path, name = self.image.rsplit('/', 1)
return ''.join((path, '/tn_', name))
class Admin:
pass