You can define image upload path at runtime (check manual for
ImageField)

def get_photo_path(instance, filename):
    return 'static/upload_to/photos/%s' % instance.name
class ProductImage(models.Model):
    name = models.CharField(max_length=50)
    file = models.ImageField(upload_to= get_photo_path)
    ...

In my projects i don't use additional field for thumbnails
Because i need thumbnails in different sizes
So i use property for that
 # If i don't allready have thumbnail in this size i generate it
 def _get_thumb_url(self, folder, size):
        if not self.photo:
            return '#'
        upload_to = path.dirname(self.photo.path)
        tiny = path.join(upload_to, folder,
path.basename(self.photo.path))
        tiny = path.normpath(tiny)
        if not path.exists(tiny):
            import Image
            im = Image.open(self.photo.path)
            im.thumbnail(size, Image.ANTIALIAS)
            im.save(tiny, 'JPEG')
        return path.join(path.dirname(self.photo.url), folder,
path.basename(self.photo.path)).replace('\\', '/')


  def get_thumb_url(self):
        return self._get_thumb_url('thumb_40_40', (40,40))

 def thumb(self):
        link = self.get_thumb_url()
        if link is None:
            return '<a href="#" target="_blank">NO IMAGE</a>'
        else:
            return '<a href="%s" target="_blank"><img src="%s"
alt="tiny thumbnail image"/></a>' % (self.photo.url, link)
 thumb.allow_tags = True

So if i need thumbnail in my template i write this:
{{ my_model.thumb }}




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to