salw/salw_admin/pssm_api/signals.py

27 lines
971 B
Python
Raw Normal View History

2024-11-28 15:06:12 +00:00
from django.db.models.signals import post_delete
from django.dispatch import receiver
from .models import Images, Impact_Stories, PSSM_Resources
import os
@receiver(post_delete, sender=Images)
def delete_image_file(sender, instance, **kwargs):
# Check if the image file exists and delete it
if instance.image:
if os.path.isfile(instance.image.path):
os.remove(instance.image.path)
@receiver(post_delete, sender=Impact_Stories)
def delete_impact_story_file(sender, instance, **kwargs):
# Check if the image file exists and delete it
if instance.file:
if os.path.isfile(instance.file.path):
os.remove(instance.file.path)
@receiver(post_delete, sender=PSSM_Resources)
def delete_pssm_resources_file(sender, instance, **kwargs):
# Check if the image file exists and delete it
if instance.file:
if os.path.isfile(instance.file.path):
os.remove(instance.file.path)