Check uniqueness before delete?
tonypottera24 opened this issue · 4 comments
I'm using django 3.2.
Assume we have a Image model, which includes a ImageField to save image.
On my local computer, if I create two Image objects and save image.jpg twice, it will produce two files.
- image.jpg
- image_ABCDE.jpg
However, on google cloud storage. https://django-storages.readthedocs.io/en/latest/backends/gcloud.html
Storing image.jpg twice will only produce one file.
- image.jpg
As a result, if I delete one Image object, another Image object cannot find the image.jpg file.
It would be nice if django-cleanup can provide an option to explicitly scan the uniqueness of the file.
Is there any way to override the delete function and add the check by myself?
This won't be supported in this library directly, as the flexibility to add this capability already exists in the django storage backend api and the uniqueness of each system prevents one library from handling all cases. You will need to implement your own solution by using a custom storage backend.
To override the delete method you can subclass your storage backend (the "GoogleCloudStorage") to change how it names files or how the delete works.
@vinnyrose thanks for your explanation.
Do you mean, django-cleanup will call the delete method when the object delete.
If I don't want to delete the object, I can override the delete method to stop the deletion?
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.