Ejemplo n.º 1
0
Archivo: views.py Proyecto: chang12/MoQ
def answer_new(request, group_pk, question_pk):
    question = get_object_or_404(Question, pk=question_pk)
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            answer = form.save(commit=False)
            answer.author = request.user
            answer.question = question
            answer.save()
            return redirect('blog:question_detail', group_pk, question_pk)

    else:
        form = AnswerForm()

    return render(request, 'blog/form.html', {
        'form': form,
    })
Ejemplo n.º 2
0
def answer_new(request, group_pk, question_pk):
    question = get_object_or_404(Question, pk=question_pk)
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            answer = form.save(commit=False)
            answer.author = request.user
            answer.question = question
            answer.save()
            return redirect('blog:question_detail', group_pk, question_pk)

    else:
        form = AnswerForm()

    return render(request, 'blog/form.html', {
        'form': form,
    })
Ejemplo n.º 3
0
Archivo: views.py Proyecto: chang12/MoQ
def answer_edit(request, group_pk, question_pk, answer_pk):
    answer = get_object_or_404(Answer, pk=answer_pk)
    if answer.author == request.user:
        if request.method == 'POST':
            form = AnswerForm(request.POST, instance=answer)
            if form.is_valid():
                form.save()
                return redirect('blog:answer_detail', group_pk, question_pk, answer_pk)
        else:
            form = AnswerForm(instance=answer)
        return render(request, 'blog/form.html', {
            'form': form,
        })

    else:
        content = '해당 답변의 작성자가 아닙니다.'
        return render(request, 'blog/error.html', {
            'content': content,
        })
Ejemplo n.º 4
0
def answer_edit(request, group_pk, question_pk, answer_pk):
    answer = get_object_or_404(Answer, pk=answer_pk)
    if answer.author == request.user:
        if request.method == 'POST':
            form = AnswerForm(request.POST, instance=answer)
            if form.is_valid():
                form.save()
                return redirect('blog:answer_detail', group_pk, question_pk,
                                answer_pk)
        else:
            form = AnswerForm(instance=answer)
        return render(request, 'blog/form.html', {
            'form': form,
        })

    else:
        content = '해당 답변의 작성자가 아닙니다.'
        return render(request, 'blog/error.html', {
            'content': content,
        })
Ejemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     form = AnswerForm(request.POST or None)
     question = get_object_or_404(Post, pk=kwargs['pk'])
     images = Images.objects.filter(post=question)
     if form.is_valid():
         newAnswer = Answer()
         newAnswer.question = question
         newAnswer.author = request.user
         newAnswer.answer = form.cleaned_data['answer']
         newAnswer.save()
         context = {
             'answers':
             Answer.objects.filter(
                 question=question).order_by('-date_posted'),
             'question':
             question,
             'images':
             images,
             'answer_form':
             AnswerForm()
         }
         return render(request, self.template_name, context)
     form = AnswerForm()
     question = get_object_or_404(Post, pk=kwargs['pk'])
     images = Images.objects.filter(post=question)
     context = {
         'answers':
         Answer.objects.filter(question=question).order_by('-date_posted'),
         'question':
         question,
         'images':
         images,
         'answer_form':
         form
     }
     return render(request, self.template_name, context)