Skip to content

Automatically deleting referenced files #34

@jayvdb

Description

@jayvdb

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions