views:

56

answers:

1

Greetings Having an ImageField object in my Foo model as such:

class Foo(models.Model):
    name = models.CharField(max_length=50)
    photo = models.ImageField(upload_to='foobar', blank=True, null=True)

I want Foo to disable to delete the uploaded photo once a Foo object is deleted and a specific . How can I do this?

Ie:

If self.name == "foo":
    #skip deleting the image from the harddisk.
+1  A: 

the best thing is to write a custom File Storage:

http://docs.djangoproject.com/en/dev/howto/custom-file-storage/#howto-custom-file-storage

override the delete method and set it the like described in

http://docs.djangoproject.com/en/dev/topics/files/#the-built-in-filesystem-storage-class

maersu