Ejemplo n.º 1
0
def question(request, number):
    q = get_object_or_404(Question, id=number)
    url = q.get_url()
    answers = Answer.objects.filter(question=q)
    if request.method == 'POST':
        form = AnswerForm(request.POST)
        form._user = request.user
        form._question = q
        if form.is_valid():
            ans = form.save()
            return HttpResponseRedirect(url)
    form = AnswerForm()
    return render(request, 'qa/question.html', {
        'question': q,
        'answers': answers,
        'form': form,
        'action': url
    })
Ejemplo n.º 2
0
def one_question_view(request, id):
    try:
        question = Question.objects.get(id=id)
    except Question.DoesNotExist:
        raise Http404
    answers = Answer.objects.filter(question=question.id)

    if request.method == "POST":
        form = AnswerForm(request.POST)
        form._user = request.user
        form._question = question
        if form.is_valid():
            answer = form.save()
            url = question.get_url()
            return HttpResponseRedirect(url)
    else:
        form = AnswerForm()

    return render(request, 'qa/question.html', {
        'question': question,
        'answers': answers,
        'form': form,
    })