When a user uploads a file, it can be used by other users to attach to their project.
class DashFile(models.Model):
dash_version = models.ForeignKey(DashVersion)
title = models.CharField(max_length=255)
file = models.FileField(upload_to=get_fs_upload_path, max_length=255)
display_order = models.IntegerField(default=99)
Basically, I clone the DashFile and so, all the values remain the same with the exception of the dash_version.
Now, if a user wants to delete the file from their project, the file gets deleted. However, that deletes the file for all other users too who have made an association to that file.
So, how can I make it so that when a user ‘deletes’ the file from their project, the file doesn’t actually get deleted?
I also know that the design choice is incorrect. I should have not used a ForeignKey but a many to many field. But I am where I am now.
Thanks
Eric
It depends on Django version that you use. From 1.2.5 version FileField never deletes files from storage backend on model.delete().
If you use Django<1.2.5 you can implement custom FileStorage: