Skip to content

Commit

Permalink
refactor(Proofs): On proof delete, also remove its images. ref #514
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Oct 11, 2024
1 parent bae2c45 commit 8360a06
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion open_prices/proofs/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.conf import settings
from django.core.validators import ValidationError
from django.db import models
from django.db.models import Count
from django.db.models import Count, signals
from django.dispatch import receiver
from django.utils import timezone

from open_prices.common import constants, utils
Expand Down Expand Up @@ -230,3 +231,13 @@ def set_missing_currency_from_prices(self):
self.prices.count(),
proof_prices_currencies_list,
)


@receiver(signals.post_delete, sender=Proof)
def proof_post_delete_remove_images(sender, instance, **kwargs):
import os

if instance.file_path_full:
os.remove(instance.file_path_full)
if instance.image_thumb_path_full:
os.remove(instance.image_thumb_path_full)

0 comments on commit 8360a06

Please sign in to comment.