first commit

This commit is contained in:
Beyhan Oğur
2026-04-26 22:22:29 +03:00
commit ec28a2024d
208 changed files with 23836 additions and 0 deletions

22
image/signals.py Normal file
View File

@@ -0,0 +1,22 @@
import os
from django.conf import settings
from django.db.models.signals import post_delete
from django.dispatch import receiver
from .models import PostImages
@receiver(post_delete, sender=PostImages)
def delete_image_file(sender, instance, **kwargs):
"""
Deletes the associated image file from the filesystem when a PostImages instance is deleted.
"""
# Check if the instance has a path and the path is not empty
if instance.path:
file_path = os.path.join(settings.MEDIA_ROOT, instance.path)
if os.path.exists(file_path):
try:
os.remove(file_path)
except OSError as e:
# Optionally, log the error e.g., print(f"Error deleting file {file_path}: {e}")
pass