Hi, after I've searched online, and from this reply  
<http://stackoverflow.com/questions/4394194/replacing-a-django-image-doesnt-delete-original#answer-8342249>I
 
have wrote this solution by overriding save method of my model class.

def save(self, force_insert=False, force_update=False, using=None, 
update_fields=None):
        # if an element exist
        if self.id is not None:
            current = MyModelClass.objects.get(id=self.id)
            if self.image != current.image:
                # Delete old image and thumbnail
                current.image.delete(save=False)    # Set save=False 
because it's saving now.
        super(MyModelClass, self).save(force_insert, force_update, using, 
update_fields).

Simple!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d9112e90-fd44-41bc-8710-e0c936082f3c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to