I am new in django and I am having problems with the removal of a file when a user uploads a new one (the old file is no longer useful for the app).
The thing is that when I user wants to update his/her profile picture, my application should remove the old one. I tried this by overriding the save function in my form UserProfileForm, related to the UserProfile model.
I have written the same lines of the save function in the shell console and it seems to work. I also tried to override the save function in the model but I got the same negative result.
I would really appreciate if anyone could give me some advice about what I am doing wrong and how should I fix it! ;)
Thank you in advance, Mario
PS: I am using the django-profiles app. It calls the save function of the form_class, which is actually my UserProfileForm. =)
One portion of my model
My form for the model
Finally the function handle_uploaded_file, which actually works fine! ;) from PIL import Image as PImage from os.path import join as pjoin from django.conf import settings
asked Nov 15 '10 at 11:48
Since it is simply failing to delete the image and is not throwing an error, then I suspect that your
answered Nov 15 '10 at 12:55
It was true what you said, but the unexpected problem (for me) was while creating a form object in my view with the following line:
This line made that the image field of my model already points to the new uploaded image. Therefore I could not delete the old one (the path to it was nowhere).
My solution was a workaround! ;) I deleted the old uploaded file by using the delete() function of the ImageField object. Then a saved the form and finally I resized my uplaoded image! ;)
Anyway, thank you very much for your help!!! ;)
answered Nov 16 '10 at 04:30