def questiongroup_update(request, room, questiongroup): if not request.method == 'POST': return HttpResponse(status=403) questiongroup = get_object_or_404(QuestionGroup, pk=questiongroup) form = VoteQuestiongroupForm(request.POST or None, instance=questiongroup) if form.is_valid(): form.save() return redirect(questiongroup) return render(request, 'vote/questiongroup_edit.html', {'questiongroup': questiongroup, 'form': form})
def questingroup_create(request, room): room = Room.objects.get(pk=room) if request.method == 'POST': if not room.owner_id == request.user.id: return redirect(room) form = VoteQuestiongroupForm(request.POST) if form.is_valid(): form.instance.owner_id = request.user.id form.instance.room_id = room.id qg = form.save() return redirect(qg) else: context = {'room': room, 'form': form} else: context = {'room': room, 'form': VoteQuestiongroupForm()} return render(request, 'vote/questiongroup_create.html', context=context)