diff --git a/ram/bookshelf/models.py b/ram/bookshelf/models.py index b9a2a30..4785c3b 100644 --- a/ram/bookshelf/models.py +++ b/ram/bookshelf/models.py @@ -1,4 +1,5 @@ import os +import shutil from uuid import uuid4 from django.db import models from django.conf import settings @@ -71,6 +72,15 @@ def publisher_name(self): def get_absolute_url(self): return reverse("book", kwargs={"uuid": self.uuid}) + def delete(self, *args, **kwargs): + shutil.rmtree( + os.path.join( + settings.MEDIA_ROOT, "images", "books", str(self.uuid) + ), + ignore_errors=True + ) + super(Book, self).delete(*args, **kwargs) + def book_image_upload(instance, filename): return os.path.join( diff --git a/ram/roster/models.py b/ram/roster/models.py index d65a017..3268335 100644 --- a/ram/roster/models.py +++ b/ram/roster/models.py @@ -1,5 +1,6 @@ import os import re +import shutil from uuid import uuid4 from django.db import models from django.urls import reverse @@ -107,6 +108,15 @@ def country(self): def company(self): return str(self.rolling_class.company) + def delete(self, *args, **kwargs): + shutil.rmtree( + os.path.join( + settings.MEDIA_ROOT, "images", "rollingstock", str(self.uuid) + ), + ignore_errors=True + ) + super(RollingStock, self).delete(*args, **kwargs) + @receiver(models.signals.pre_save, sender=RollingStock) def pre_save_running_number(sender, instance, *args, **kwargs):