From 55482d226210da88954b58dc520e869a4644a862 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Wed, 6 Jan 2021 13:59:37 +0100 Subject: [PATCH] Fix upload paths for StatusMedia --- mood/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mood/views.py b/mood/views.py index 8444aee..01604cd 100644 --- a/mood/views.py +++ b/mood/views.py @@ -7,6 +7,7 @@ from django.http import HttpResponseRedirect from .models import Status, Activity, Mood, StatusMedia, StatusActivity from .forms import StatusForm +from common.helpers import get_upload_path from msgio.models import NotificationDailySchedule, Notification class StatusListView(LoginRequiredMixin, ListView): @@ -61,7 +62,9 @@ class StatusCreateView(LoginRequiredMixin, CreateView): StatusActivity.objects.create(activity=activity, status=form.instance) for attachment in form.cleaned_data["uploads"]: - StatusMedia.objects.create(status=form.instance, file=attachment) + dba = StatusMedia(status=form.instance) + dba.file.save(get_upload_path(form.instance, attachment.name), attachment) + dba.save() return ret @@ -87,7 +90,9 @@ class StatusEditView(LoginRequiredMixin, UpdateView): def form_valid(self, form): for attachment in form.cleaned_data["uploads"]: - StatusMedia.objects.create(status=form.instance, file=attachment) + dba = StatusMedia(status=form.instance) + dba.file.save(get_upload_path(form.instance, attachment.name), attachment) + dba.save() for activity in form.cleaned_data["activities"]: if activity.user == self.request.user: