diff --git a/alexandria/core/models.py b/alexandria/core/models.py index 5e70bba6..df6450ab 100644 --- a/alexandria/core/models.py +++ b/alexandria/core/models.py @@ -211,7 +211,7 @@ class Meta: ordering = ["-created_at"] -@receiver(models.signals.pre_delete, sender=File) +@receiver(models.signals.post_delete, sender=File) def auto_delete_file_on_delete(sender, instance, **kwargs): """Delete file from filesystem when `File` object is deleted.""" diff --git a/alexandria/core/utils.py b/alexandria/core/utils.py index ec00b6fa..7e51f191 100644 --- a/alexandria/core/utils.py +++ b/alexandria/core/utils.py @@ -11,7 +11,7 @@ from alexandria.core.models import File -def create_thumbnail(_file): +def create_thumbnail(_file: File): with NamedTemporaryFile() as tmp: temp_file = Path(tmp.name) manager = PreviewManager(str(temp_file.parent)) @@ -33,7 +33,7 @@ def create_thumbnail(_file): with path_to_preview_image.open("rb") as thumb: thumb_file = File.objects.create( - name=f"{_file.name}.jpg", + name=f"{_file.name}_preview.jpg", document=_file.document, variant=File.Variant.THUMBNAIL.value, original=_file,