CS50W商业项目:'竞标必须与开始出价一样大,并且必须比其他任何出现(如果有)的其他出价大?
我已经解决了这个特殊的问题,但是我注意到了一些问题,但没有得到为什么它的行为。
以下代码以我希望其工作的方式工作:
@login_required
def bid_placed(request,listing_id):
if request.method == "POST":
recent_bid = Bid(
Bid_amount = request.POST["bid_amount"],
listing = Listing.objects.get(pk=listing_id)
)
listing = Listing.objects.get(pk=listing_id)
starting_Bid = listing.Starting_Bid
recent_bid_int = int(recent_bid.Bid_amount)
if recent_bid_int > starting_Bid:
listing.Starting_Bid = recent_bid_int
listing.save()
return HttpResponse("Bid SUCCESSFULLY Placed")
else:
return HttpResponse("Bid CANNOT be placed")
但是,即使已经声明了starting_bid
变量,下面的代码也无法根据需要工作:
@login_required
def bid_placed(request,listing_id):
if request.method == "POST":
recent_bid = Bid(
Bid_amount = request.POST["bid_amount"],
listing = Listing.objects.get(pk=listing_id)
)
listing = Listing.objects.get(pk=listing_id)
starting_Bid = listing.Starting_Bid
recent_bid_int = int(recent_bid.Bid_amount)
if recent_bid_int > starting_Bid:
starting_Bid = recent_bid_int
listing.save()
return HttpResponse("Bid SUCCESSFULLY Placed")
else:
return HttpResponse("Bid CANNOT be placed")
有人可以解释为什么可能是这种情况吗?
I have solved this particular problem, but there is something that I noticed and didn't get why was it behaving the way it did.
The below code worked the way I wanted it to work:
@login_required
def bid_placed(request,listing_id):
if request.method == "POST":
recent_bid = Bid(
Bid_amount = request.POST["bid_amount"],
listing = Listing.objects.get(pk=listing_id)
)
listing = Listing.objects.get(pk=listing_id)
starting_Bid = listing.Starting_Bid
recent_bid_int = int(recent_bid.Bid_amount)
if recent_bid_int > starting_Bid:
listing.Starting_Bid = recent_bid_int
listing.save()
return HttpResponse("Bid SUCCESSFULLY Placed")
else:
return HttpResponse("Bid CANNOT be placed")
But the below code is NOT working as desired, even though the starting_Bid
variable has been declared:
@login_required
def bid_placed(request,listing_id):
if request.method == "POST":
recent_bid = Bid(
Bid_amount = request.POST["bid_amount"],
listing = Listing.objects.get(pk=listing_id)
)
listing = Listing.objects.get(pk=listing_id)
starting_Bid = listing.Starting_Bid
recent_bid_int = int(recent_bid.Bid_amount)
if recent_bid_int > starting_Bid:
starting_Bid = recent_bid_int
listing.save()
return HttpResponse("Bid SUCCESSFULLY Placed")
else:
return HttpResponse("Bid CANNOT be placed")
Can someone please explain why it might be the case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论