From 3e6ef52be9156e5a9a738950973c3d157db1b914 Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 6 Jan 2021 13:55:32 +0100 Subject: [PATCH] Fix attachment upload paths for DreamMedia --- dreams/views.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dreams/views.py b/dreams/views.py index 01db574..423bd07 100644 --- a/dreams/views.py +++ b/dreams/views.py @@ -9,6 +9,7 @@ from django.http import HttpResponseRedirect from .models import Dream, DreamTheme, DreamMedia, Theme from .forms import DreamForm +from common.helpers import get_upload_path from msgio.models import NotificationDailySchedule, Notification class DreamListView(LoginRequiredMixin, ListView): @@ -63,7 +64,9 @@ class DreamCreateView(LoginRequiredMixin, CreateView): DreamTheme.objects.create(theme=theme, dream=form.instance) for attachment in form.cleaned_data["uploads"]: - DreamMedia.objects.create(dream=form.instance, media=attachment) + dba = DreamMedia(dream=form.instance) + dba.media.save(get_upload_path(form.instance, dba.media.name), attachment) + dba.save() return ret @@ -97,8 +100,10 @@ class DreamEditView(LoginRequiredMixin, UpdateView): if not dreamtheme.theme in form.cleaned_data["themes"]: dreamtheme.delete() - for upload in form.cleaned_data["uploads"]: - DreamMedia.objects.create(dream=form.instance, media=upload) + for attachment in form.cleaned_data["uploads"]: + dba = DreamMedia(dream=form.instance) + dba.media.save(get_upload_path(form.instance, attachment.name), attachment) + dba.save() return super().form_valid(form)