def update_ord(request, id_test): order = Order.objects.get(id=id_test) form = OrderForm(instance=order) if request.method == 'POST': form = OrderForm(request.POST, instance=order) if form.is_valid(): form.save() return redirect('home') else: bad = form.errors print(bad) context = {'bad': bad} context = {'form': form} return render(request, 'create_order.html', context)
def create_ord(request, id_test): customer = Customer.objects.get(id=id_test) form = OrderForm(initial={'customer': customer}) if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): form.save() return redirect('home') else: bad = form.errors print(bad) context = {'bad': bad} context = {'form': form} return render(request, 'create_order.html', context)
def checkout(request): if request.method == "GET": f = OrderForm() return render_to_response("home/checkout.html", {'form' : f}, context_instance=RequestContext(request)) if request.method == "POST": form = OrderForm(request.POST) if form.is_valid(): products = request.session["shopping_card"] strPro = "" for product in products: strPro += "product_id: " + str(product["product_id"]) + " => num :" + str(product["num"]) f = form.save(commit=False) f.note += strPro f.save() del request.session["shopping_card"] return render_to_response('home/_success.html', context_instance=RequestContext(request)) else: return render_to_response('home/checkout.html', {'form': form}, context_instance=RequestContext(request))
def order(request, slug): method = get_object_or_404(Method, slug=slug) user = auth.get_user(request) if request.method == 'POST': form = OrderForm(data=request.POST, initial={ 'method': method, 'author': user }) if form.is_valid(): new_comment = form.save(commit=False) new_comment.method = method new_comment.author = user print(new_comment) new_comment.save() return render(request, 'home/order_complated.html') else: form = OrderForm(initial={'method': method, 'author': user}) return render(request, 'home/method_order.html', locals())