i can uplad file and servin him from django. but when i will resize
(with PIL) the upladed file i con't.
when i make
im = Image.open(PATH_TO_IMAGE+self.ImageFieldName)
the self.ImageFieldName is Null/''
without this line all is ok !!!
mayby you can wrot a example for me: how to resize or rotate a image
thats bean just uploaded?
ther is my model, im come from poland and labels are in polish.
this will be a wery semple gallery. i wont upload a {{plik}} and make
a thumb = {{male}} and a preview = {{duze}} in _post_save()
# -*- coding: utf-8 -*-
from django.core import meta
from aparatura.settings.main import MEDIA_ROOT
class galeria(meta.Model):
nazwa = meta.CharField(maxlength=64)
opis = meta.TextField()
class META:
admin = meta.Admin(
js =
('/media/js/tiny_mce/tiny_mce.js','/media/js/tiny_mce/textareas.js'),
)
def __repr__(self):
return self.nazwa
class zdjecie(meta.Model):
galeria = meta.ForeignKey(galeria)
nazwa = meta.CharField(maxlength=64)
opis = meta.TextField()
plik =
meta.ImageField(blank=False,null=False,upload_to=MEDIA_ROOT+'/zdjecia/')
male = meta.ImageField(blank=True,default='brak.png')
duze = meta.ImageField(blank=True,default='brak.png')
class META:
admin = meta.Admin(
js =
('/media/js/tiny_mce/tiny_mce.js','/media/js/tiny_mce/textareas.js'),
list_display = ('nazwa', 'opis', 'plik','male','duze'),
)
def __repr__(self):
return self.nazwa
def _pre_save(self):
self.male=self.plik+'.male.png'
self.duze=self.plik+'.duze.png'
self.nazwa = self.plik
def _post_save(self):
from aparatura.settings.main import MEDIA_ROOT
from PIL import Image
i8 = open(self.get_plik_filename()+self.plik)
x1 = 100
x2 = 640
y1 = im.size[1]/(im.size[0]/x1)
y2 = im.size[1]/(im.size[0]/x2)
i1 = im.resize((x1,y1),Image.ANTIALIAS)
i2 = im.resize((x2,y2),Image.ANTIALIAS)
i1.save(MEDIA_ROOT+'/'+self.male,'PNG')
i2.save(MEDIA_ROOT+'/'+self.duze,'PNG')