Exemplo n.º 1
0
def edit_answer(request, answer_id):
    answer = get_object_or_404(Answer, id=answer_id)

    if request.method == 'POST':
        form = AnswerForm(request.POST, instance=answer)
        if form.is_valid():
            form.save()

            return HttpResponseRedirect('/audits/item/gestor/details/%s' % answer.item.id)
    else:
        form = AnswerForm(instance=answer)

    return render(request, 'form.html', {'form': form, 'back_url': '/audits/item/gestor/details/%s' % answer.item_id})
Exemplo n.º 2
0
def create_answer(request, item_id):
    item = get_object_or_404(Item, id=item_id)

    if request.method == 'POST':
        form = AnswerForm(request.POST)
        if form.is_valid():
            answer = form.save(commit=False)
            answer.item = item
            answer.save()

            response = {}
            response['id'] = answer.id
            response['name'] = answer.name
            response['value'] = answer.value

            return JsonResponse(response)
        else:
            return JsonResponse(form.errors)
    else:
        return JsonResponse({"sorry": "bad method"})