コード例 #1
0
def buy(request):
    gid=request.GET['id']
    good=Goods.objects(pk=gid).first()
    buylog=Buy()
    buylog.good=good
    request.user.buylog=request.user.buylog+[buylog]
    request.user.save()
    return HttpResponse("buy success")
コード例 #2
0
ファイル: views.py プロジェクト: sivajipr/flipkart
def buy_product(request, address_id, product_id):
	user = request.user
	address = Address.objects.get(id=address_id)
	product = Product.objects.get(id=product_id)
	if request.method =='POST':
		form = BuyForm(request.POST)
		if (product.quantity-form.cleaned_data['quantity'])>=0:
			product.quantity = product.quantity-form.cleaned_data['quantity']
			buy = Buy(user=user, address=address,product=product,status=1, quantity=form.cleaned_data['quantity'])
			buy.save()
			product.save()
			return HttpResponse()
		else:
			error = '%d pieces are not available' %form.cleaned_data['quantity']
			data = {'error':error}
			return HttpResponse(json.dumps(data), content_type="application/json")
	else:
		form = BuyForm()
	variables = RequestContext(request, {'form': form, 'product':product,'address':address})
	return render_to_response('product/buy_conform.html', variables)