Use uploaded filename for destination
This commit is contained in:
parent
732b33539a
commit
1ffc0934dd
1 changed files with 3 additions and 3 deletions
|
|
@ -122,8 +122,8 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
|
||||||
# We take files from the request to support multiple upload
|
# We take files from the request to support multiple upload
|
||||||
files = self.request.FILES.getlist('file_field')
|
files = self.request.FILES.getlist('file_field')
|
||||||
gallery = form.get_or_create_gallery()
|
gallery = form.get_or_create_gallery()
|
||||||
gallery_year = str(gallery.extended.date_start.year)
|
gallery_year = Path(str(gallery.extended.date_start.year))
|
||||||
gallery_dir = Path('photos') / gallery_year / gallery.slug
|
gallery_dir = gallery_year / gallery.slug
|
||||||
failed_upload = 0
|
failed_upload = 0
|
||||||
for photo_file in files:
|
for photo_file in files:
|
||||||
# Check that we have a valid image
|
# Check that we have a valid image
|
||||||
|
|
@ -139,7 +139,7 @@ class GalleryUpload(PermissionRequiredMixin, FormView):
|
||||||
title = f"{gallery.title} - {photo_file.name}"
|
title = f"{gallery.title} - {photo_file.name}"
|
||||||
try:
|
try:
|
||||||
photo = Photo(title=title, slug=slugify(title))
|
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.image.save(photo_name, photo_file)
|
||||||
photo.save()
|
photo.save()
|
||||||
photo.galleries.set([gallery])
|
photo.galleries.set([gallery])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue