def edit_message(request, quest_id, message_id): quest = get_object_or_404(Quest, pk=quest_id, parent__isnull=True) request = is_quest_organizer(request, quest) message = get_object_or_404(Message, pk=message_id) if request.method == "POST": form = MessageForm(request.POST, instance=message) if form.is_valid(): form.save() return redirect('coordination:quest_messages', quest_id=quest_id) else: form = MessageForm(instance=message) context = {'form': form} return render(request, 'coordination/messages/form.html', context)
def messages_quest(request, quest_id): quest = get_object_or_404(Quest, pk=quest_id, parent__isnull=True) request = is_quest_organizer(request, quest) messages = quest.messages() if request.method == 'POST': form = MessageForm(request.POST) if form.is_valid(): message = form.save(commit=False) message.quest = quest message.save() return redirect('coordination:quest_messages', quest_id=quest.id) else: form = MessageForm() context = {'quest': quest, 'messages': messages, 'form': form} return render(request, 'coordination/quests/messages.html', context)