I am trying to convert a Pillow image to Django ImageField.
Basically, I:
- Take an
ImageField
as input (from a user submitted form) - Open it with
Pillow
- Process it (blur it in that case)
- Pass it back to my Django Form
- Try to save the Form ⚠️
This is at the last step that I have the error 'Image' object has no attribute '_committed'
(which I believe is that Django is unable to save a Pillow image and that it needs to be converted)
def upload_media(request):
if request.method == 'POST':
form = PostForm(request.POST, request.FILES)
if form.is_valid():
image = form.cleaned_data['image']
pil_image = Image.open(image)
blurred_image = pil_image.filter(ImageFilter.GaussianBlur(100))
post = Post(image=image, blurred_image=blurred_image)
post.save()
return redirect('index')