On Aug 6, 8:36 pm, zayatzz <alan.kesselm...@gmail.com> wrote: > Hello > > I am not entirely sure if i am asking the right question, but here is > what am trying to do. > > I am saving user mugshot with form and it works just fine. I rename > the uploaded file to mugshot.[insert imagefile extension here], but i > want to do more in form save method than just that. > > 1) i want to check if the model, whos form im saving already has > imagefile saved. I have this in view: > pform = ProfileForm(instance=profile) > > but this in form save: > os.remove(settings.MEDIA_ROOT+self.instance.img) > > returns me ImageFieldFile not the data that is saved in it... and i > get typeerror: > TypeError at /profile/edit/ > > cannot concatenate 'str' and 'ImageFieldFile' objects > > 2) if it exists, then remove it - can do it os.remove(), but the > problem is similar to last point - i need to know the name of existing > file, that is saved in model data > 3) if the file has been removed or did not exist in the first place > then i want to save different sizes of the file - thumbnail, bigger > pic and so on. i do not need the examples for that. > > Alan
self.instance.img.name will give you the relative path from MEDIA_ROOT. See: http://docs.djangoproject.com/en/dev/ref/files/file/#django.core.files.File.name -- DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---