Skip to content

Commit

Permalink
delete files after model instance deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumandari committed Nov 8, 2021
1 parent eaa9781 commit 7c76865
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions qgis-app/base/models/processing_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import datetime
import uuid
import os

from django.db import models
from django.contrib.auth.models import User
Expand Down Expand Up @@ -121,6 +122,11 @@ def save(self, *args, **kwargs):
self.modified_date = datetime.datetime.now()
super().save(*args, **kwargs)

def delete(self, *args, **kwargs):
if os.path.isfile(self.file.path):
os.remove(self.file.path)
super(Resource, self).delete(*args, **kwargs)

def __str__(self):
return "%s" % (self.name)

Expand Down
9 changes: 9 additions & 0 deletions qgis-app/wavefronts/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil

from preferences.models import Preferences

Expand Down Expand Up @@ -45,6 +46,14 @@ def extension(self):
def get_absolute_url(self):
return reverse('wavefront_detail', args=(self.id,))

def delete(self, *args, **kwargs):
if os.path.isfile(self.file.path):
path, _ = os.path.split(self.file.path)
if not path.endswith(WAVEFRONTS_STORAGE_PATH):
# remove folder and the content
shutil.rmtree(path)
super(Wavefront, self).delete(*args, **kwargs)


class Review(ResourceReview):
"""
Expand Down

0 comments on commit 7c76865

Please sign in to comment.