I have a image field in the model. I need to make two copies(resized) of that image to another two field(thumb_big and thumb_small). Thumb_big will be 225px width, height could be anything. and thumb_small is 65x50px.
I searched but nothing seems to fit in my problem. I Have installed PIL. Tried django-imagekit, some other snipets.
If you know any link that will be great also, BTW I am a django newbie but you assume that already, right?
here is my model
class Photo(models.Model):
title = models.CharField(max_length=500)
pub_date = models.DateField(auto_now_add=True)
mod_date = models.DateField(auto_now=True)
slug_name = models.SlugField(max_length=500)
image = models.ImageField(upload_to='interview', blank=True)
thumb_big = models.ImageField(upload_to= 'interview/thumbs_big', blank=True)
thumb_small = models.ImageField(upload_to= 'interview/thumbs_small', blank=True)
category = models.CharField(max_length=200, blank=True)
details = models.TextField()
def __unicode__(self):
return self.title
I’m not quite sure why would you need to store thumbnail paths in the database.
There are several django thumbnail applications.
Two of my favorites are:
Both of them are using template tags for generating thumbnails on the fly,
and display them in your django templates.
They also come with custom database fields to make thumbnail management easier:
http://thumbnail.sorl.net/examples.html#model-examples
http://packages.python.org/easy-thumbnails/usage.html#models
If you really need to save paths to your thumbnails in your model, you can generate both thumbnails in your image upload view, and then assign resulting file paths to corresponding database fields. With easy thumbnail it will look like: