From 52d86d0bc6693910433335d95e3935ff8da1b50c Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 28 Dec 2020 22:32:32 +0100 Subject: [PATCH] Fix form validation for Status changes --- mood/views.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mood/views.py b/mood/views.py index cf726a6..d6f5779 100644 --- a/mood/views.py +++ b/mood/views.py @@ -88,15 +88,12 @@ class StatusEditView(LoginRequiredMixin, UpdateView): StatusMedia.objects.create(status=form.instance, file=attachment) for activity in form.cleaned_data["activities"]: - try: - aobj = Activity.objects.get(user=self.request.user, id=activity) - if not aobj in form.instance.activity_set: - StatusActivity.objects.create(activity=aobj, status=form.instance) - except Activity.DoesNotExist: - pass + if activity.user == self.request.user: + if not activity in form.instance.activity_set: + StatusActivity.objects.create(activity=activity, status=form.instance) for statusactivity in form.instance.statusactivity_set.all(): - if not statusactivity.activity.id in form.cleaned_data["activities"]: + if not statusactivity.activity in form.cleaned_data["activities"]: statusactivity.delete() return super().form_valid(form)