diff --git a/CHANGES/7316.feature b/CHANGES/7316.feature new file mode 100644 index 0000000000..ecbfd4c4d5 --- /dev/null +++ b/CHANGES/7316.feature @@ -0,0 +1 @@ +Added the django-cleanup handlers for removing files stored within FileField diff --git a/CHANGES/plugin_api/7316.feature b/CHANGES/plugin_api/7316.feature new file mode 100644 index 0000000000..0e90fd502e --- /dev/null +++ b/CHANGES/plugin_api/7316.feature @@ -0,0 +1,2 @@ +Enabled the automatic removal of files, which are stored in FileField, when a corresponding +model's delete() method is invoked diff --git a/pulpcore/app/models/content.py b/pulpcore/app/models/content.py index 5bac9b6aee..a690d6c64d 100644 --- a/pulpcore/app/models/content.py +++ b/pulpcore/app/models/content.py @@ -95,17 +95,6 @@ def save(self, *args, **kwargs): finally: self.file.close() - def delete(self, *args, **kwargs): - """ - Deletes Model and the file associated with the Model - - Args: - args (list): list of positional arguments for Model.delete() - kwargs (dict): dictionary of keyword arguments to pass to Model.delete() - """ - super().delete(*args, **kwargs) - self.file.delete(save=False) - class Artifact(HandleTempFilesMixin, BaseModel): """ diff --git a/pulpcore/app/models/upload.py b/pulpcore/app/models/upload.py index 1440cddccc..fa3de932ae 100644 --- a/pulpcore/app/models/upload.py +++ b/pulpcore/app/models/upload.py @@ -46,17 +46,6 @@ def append(self, chunk, offset, sha256=None): self.chunks.create(offset=offset, size=len(chunk)) - def delete(self, *args, **kwargs): - """ - Deletes Upload model and the file associated with the model - - Args: - args (list): list of positional arguments for Model.delete() - kwargs (dict): dictionary of keyword arguments to pass to Model.delete() - """ - super().delete(*args, **kwargs) - self.file.delete(save=False) - class UploadChunk(BaseModel): """ diff --git a/pulpcore/app/settings.py b/pulpcore/app/settings.py index 51a8d9bbae..ac08c417f7 100644 --- a/pulpcore/app/settings.py +++ b/pulpcore/app/settings.py @@ -65,6 +65,8 @@ "rest_framework", # pulp core app "pulpcore.app", + # the cleanup config has to be placed last + "django_cleanup.apps.CleanupConfig", ] # Enumerate the installed Pulp plugins during the loading process for use in the status API diff --git a/requirements.txt b/requirements.txt index eb86147ff1..a7cdf306d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ aiofiles backoff Django~=2.2.14 # LTS version, switch only if we have a compelling reason to django-currentuser~=0.5.1 +django-cleanup~=5.0.0 django-filter~=2.3.0 django-guardian~=2.3.0 django-import-export~=2.3.0