From 1d2a3e84b578fea763032c8e5c14ffd61d6c5084 Mon Sep 17 00:00:00 2001 From: Horilla Date: Thu, 15 May 2025 15:16:14 +0530 Subject: [PATCH] [UPDT] FACEDETECTION: Employee face detect image delete --- facedetection/forms.py | 6 +++--- facedetection/models.py | 11 +++++++++++ facedetection/templates/face_config.html | 3 +-- facedetection/views.py | 1 - 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/facedetection/forms.py b/facedetection/forms.py index 470a91850..5b388b9ce 100644 --- a/facedetection/forms.py +++ b/facedetection/forms.py @@ -1,11 +1,12 @@ +from django.template.loader import render_to_string from base.forms import ModelForm from facedetection.models import FaceDetection -from django.template.loader import render_to_string + class FaceDetectionSetupForm(ModelForm): verbose_name = "Facedetection Configuration" - + class Meta: model = FaceDetection exclude = ["company_id"] @@ -17,4 +18,3 @@ class FaceDetectionSetupForm(ModelForm): context = {"form": self} table_html = render_to_string("common_form.html", context) return table_html - \ No newline at end of file diff --git a/facedetection/models.py b/facedetection/models.py index 0d22b766f..aa63e586d 100644 --- a/facedetection/models.py +++ b/facedetection/models.py @@ -1,4 +1,8 @@ +import os + from django.db import models +from django.db.models.signals import post_delete +from django.dispatch import receiver # Create your models here. @@ -15,3 +19,10 @@ class EmployeeFaceDetection(models.Model): "employee.Employee", related_name="face_detection", on_delete=models.CASCADE ) image = models.ImageField() + + +@receiver(post_delete, sender=EmployeeFaceDetection) +def delete_image_file(sender, instance, **kwargs): + if instance.image and instance.image.path: + if os.path.isfile(instance.image.path): + os.remove(instance.image.path) diff --git a/facedetection/templates/face_config.html b/facedetection/templates/face_config.html index c0b05ad70..320733f95 100644 --- a/facedetection/templates/face_config.html +++ b/facedetection/templates/face_config.html @@ -1,5 +1,4 @@
{% csrf_token %} {{form.as_p}} - -
\ No newline at end of file + diff --git a/facedetection/views.py b/facedetection/views.py index 16609db6e..3133f9419 100644 --- a/facedetection/views.py +++ b/facedetection/views.py @@ -141,7 +141,6 @@ def get_facedetection(request): @permission_required("geofencing.add_localbackup") @hx_request_required def face_detection_config(request): - print(">>>>>>>>>>>>>>>>>>>>>") try: form = FaceDetectionSetupForm(instance=get_facedetection(request)) except: