def post(self, request, pk, *args, **kwargs): t = TodoItem.objects.get(id=pk) form = AddTaskForm(request.POST, instance=t) if form.is_valid(): new_task = form.save(commit=False) new_task.owner = request.user new_task.save() form.save_m2m() return HttpResponseRedirect(reverse("tasks:list")) return render(request, "tasks/edit.html", {"form": form, "task": t})
def post(self, request, *args, **kwargs): form = AddTaskForm(request.POST) if form.is_valid(): # form.save() # подмешаем юзера в форму new_task = form.save(commit=False) new_task.owner = request.user new_task.save() # чтобы сохранить теги (по дефолту поля m2m не сохраняются при commit=False) form.save_m2m() return HttpResponseRedirect(reverse('tasks:list')) return self.my_render(request, form)