I am trying to switch form a functional view that edits and submits a form to class based view, UpdateView. I need to access the form.
Until now I use this view:
@login_required def edit_sale_view(request, id): instance = get_object_or_404(Sale, id=id) form = EditSaleForm(instance=instance) if request.method == "POST": form = EditSaleForm(request.POST, instance=instance) if form.is_valid(): obj = form.save(commit=False) obj.user = request.user obj.save() return JsonResponse({'msg': 'Data saved'}) else: return JsonResponse({'msg': 'Data not saved'}) return HttpResponse(form.as_p())
Theform.as_p()is important because it is used in the form that is displayed in a modal window.
form.as_p()
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here