From 1ffc0934dd9f6ba3a3bad2615aa8608de8d0b303 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Wed, 15 Dec 2021 20:29:45 +0100 Subject: [PATCH] Use uploaded filename for destination --- photologue_custom/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/photologue_custom/views.py b/photologue_custom/views.py index 7853658..04bfa69 100644 --- a/photologue_custom/views.py +++ b/photologue_custom/views.py @@ -122,8 +122,8 @@ class GalleryUpload(PermissionRequiredMixin, FormView): # We take files from the request to support multiple upload files = self.request.FILES.getlist('file_field') gallery = form.get_or_create_gallery() - gallery_year = str(gallery.extended.date_start.year) - gallery_dir = Path('photos') / gallery_year / gallery.slug + gallery_year = Path(str(gallery.extended.date_start.year)) + gallery_dir = gallery_year / gallery.slug failed_upload = 0 for photo_file in files: # Check that we have a valid image @@ -139,7 +139,7 @@ class GalleryUpload(PermissionRequiredMixin, FormView): title = f"{gallery.title} - {photo_file.name}" try: photo = Photo(title=title, slug=slugify(title)) - photo_name = str(gallery_dir / photo.image.name.split("/")[-1]) + photo_name = str(gallery_dir / photo_file.name) photo.image.save(photo_name, photo_file) photo.save() photo.galleries.set([gallery])