Skip to content

Automatically deleting referenced files #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jayvdb opened this issue Aug 26, 2020 · 0 comments
Open

Automatically deleting referenced files #34

jayvdb opened this issue Aug 26, 2020 · 0 comments

Comments

@jayvdb
Copy link
Contributor

jayvdb commented Aug 26, 2020

The README says

"Note that when a field referencing a file is cleared, the corresponding file in the database and on the file system will not be automatically deleted"

https://django-db-file-storage.readthedocs.io/en/master/#models contains an example of how to add automatic deletion for their solution:

from db_file_storage.model_utils import delete_file, delete_file_if_needed
from django.db import models

class Console(models.Model):
    name = models.CharField(max_length=100, unique=True)
    picture = models.ImageField(..., blank=True, null=True)

    def save(self, *args, **kwargs):
        delete_file_if_needed(self, 'picture')
        super(Console, self).save(*args, **kwargs)

    def delete(self, *args, **kwargs):
        super(Console, self).delete(*args, **kwargs)
        delete_file(self, 'picture')

Can something like that be added here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant