From 68e047560103f8b2bf9693dcd87e58732438e29d Mon Sep 17 00:00:00 2001 From: Vitali Yanushchyk Date: Mon, 21 Oct 2024 09:09:16 -0300 Subject: [PATCH] add ! model Config at the admin panel --- src/hope_dedup_engine/apps/api/admin/__init__.py | 1 + src/hope_dedup_engine/apps/api/admin/config.py | 8 ++++++++ src/hope_dedup_engine/apps/api/models/__init__.py | 1 + .../apps/api/models/deduplication.py | 13 ++++++++++++- src/hope_dedup_engine/apps/faces/admin.py | 1 - 5 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/hope_dedup_engine/apps/api/admin/config.py diff --git a/src/hope_dedup_engine/apps/api/admin/__init__.py b/src/hope_dedup_engine/apps/api/admin/__init__.py index 1f932710..2cd9c3d5 100644 --- a/src/hope_dedup_engine/apps/api/admin/__init__.py +++ b/src/hope_dedup_engine/apps/api/admin/__init__.py @@ -1,5 +1,6 @@ from django.contrib import admin +from .config import ConfigAdmin # noqa from .deduplicationset import DeduplicationSetAdmin # noqa from .duplicate import DuplicateAdmin # noqa from .hdetoken import HDETokenAdmin # noqa diff --git a/src/hope_dedup_engine/apps/api/admin/config.py b/src/hope_dedup_engine/apps/api/admin/config.py new file mode 100644 index 00000000..18d4320f --- /dev/null +++ b/src/hope_dedup_engine/apps/api/admin/config.py @@ -0,0 +1,8 @@ +from django.contrib.admin import ModelAdmin, register + +from hope_dedup_engine.apps.api.models import Config + + +@register(Config) +class ConfigAdmin(ModelAdmin): + pass diff --git a/src/hope_dedup_engine/apps/api/models/__init__.py b/src/hope_dedup_engine/apps/api/models/__init__.py index 40bdb2fa..3192920e 100644 --- a/src/hope_dedup_engine/apps/api/models/__init__.py +++ b/src/hope_dedup_engine/apps/api/models/__init__.py @@ -1,5 +1,6 @@ from hope_dedup_engine.apps.api.models.auth import HDEToken # noqa: F401 from hope_dedup_engine.apps.api.models.deduplication import ( # noqa: F401 + Config, DeduplicationSet, Duplicate, Image, diff --git a/src/hope_dedup_engine/apps/api/models/deduplication.py b/src/hope_dedup_engine/apps/api/models/deduplication.py index f42d2047..95cb6955 100644 --- a/src/hope_dedup_engine/apps/api/models/deduplication.py +++ b/src/hope_dedup_engine/apps/api/models/deduplication.py @@ -2,6 +2,7 @@ from uuid import uuid4 from django.conf import settings +from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models from hope_dedup_engine.apps.api.utils.notification import send_notification @@ -11,7 +12,17 @@ class Config(models.Model): - face_distance_threshold = models.FloatField(null=True) + face_distance_threshold = models.FloatField( + null=True, + validators=[MinValueValidator(0.1), MaxValueValidator(1.0)], + ) + + def __str__(self) -> str: + return " | ".join( + f"{field.name}: {getattr(self, field.name)}" + for field in self._meta.fields + if field.name not in ("id",) + ) class DeduplicationSet(models.Model): diff --git a/src/hope_dedup_engine/apps/faces/admin.py b/src/hope_dedup_engine/apps/faces/admin.py index 6fd74cff..efa34eaf 100644 --- a/src/hope_dedup_engine/apps/faces/admin.py +++ b/src/hope_dedup_engine/apps/faces/admin.py @@ -45,7 +45,6 @@ def sync_dnn_files(self, request): else: worker_count = len(active_workers) if worker_count > 1: - print(f"{worker_count=}") job = group(sync_dnn_files.s(force=True) for _ in range(worker_count)) result = job.apply_async() self.message_user(