Skip to content

Commit

Permalink
Delete roster and bookshelf images on delte.
Browse files Browse the repository at this point in the history
Do not delete others data that might be dedup
  • Loading branch information
daniviga committed Oct 31, 2023
1 parent cb3c838 commit bfe9a68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ram/bookshelf/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shutil
from uuid import uuid4
from django.db import models
from django.conf import settings
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions ram/roster/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import re
import shutil
from uuid import uuid4
from django.db import models
from django.urls import reverse
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit bfe9a68

Please sign in to comment.