Hay guys, I've wrote a simple upload method for my pictures
class Picture(models.Model):
path = models.CharField(max_length=200)
filename = models.CharField(max_length=200)
car = models.ForeignKey('Car')
thumb_path = models.CharField(max_length=200)
created_on = models.DateField(auto_now_add=True)
updated_on = models.DateField(auto_now=True)
def save(self):
if not self.id:
thumb_size = 128, 128
thumb_path = "assests/uploads/thumb"+self.filename
t = Image.open(self.path)
t.thumbnail(thumb_size,Image.ANTIALIAS)
t.save(thumb_path, "JPEG")
self.thumb_path = thumb_path
super(Picture, self).save()
def delete(self):
os.unlink(self.thumb_path)
os.unlink(self.path)
super(Picture, self).delete()
As you can see this isn't the best method, i want to move on to the ImageField() to do most of my work, but i still want the flexiability to create a thumbnail and random filename.
would i need to create another model for PictureThumbnail? I don't really want to use any 3rd part extensions.
how could i use ImageField to make this work? All the iamges are gong to be uploaded to /assests/uploads/
Thanks