[UPDT] FACEDETECTION: Employee face detect image delete

This commit is contained in:
Horilla
2025-05-15 15:16:14 +05:30
parent 7a83920581
commit 1d2a3e84b5
4 changed files with 15 additions and 6 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -1,5 +1,4 @@
<form hx-post="{% url 'face-config' %}" hx-swap="none" hx-on-htmx-after-request="$('#reloadMessagesButton').click();">
{% csrf_token %}
{{form.as_p}}
</form>
</form>

View File

@@ -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: