def add_bid(request): bidder, item_name, amount = read_request_item(request) #Check if item is sold if is_sold(item_name): return messages['SOLD_MESSAGE'] #search for the bid using bidder and item_name bid = get_bid(bidder = bidder, item_name=item_name) #if bid is present update the bid amount else create bid if bid: bid = modify_bid(bid=bid[0], amount=amount) bid_action="Modified" else: bid = create_bid(item = item_name, bidder = bidder, bid_amount= amount) bid_action="Created" #notify all bidders for this item notify(item= item_name, username= bidder, bid_amount= amount) return "{0} Bid: {1} {2}".format(bid_action, bid.item, bid.bid_amount)
def add_bid(request): bidder, item_name, amount = read_request_item(request) item = Items.objects.get(item_name = item_name) if is_sold(item): return ("Cannot Bid: {0}. Item already sold".format(item_name)) else: try: bid = bids.objects.get(item = item, bidder = bidder ) except bids.DoesNotExist: bid = bids.objects.create(bidder = bidder, item = item, bid_amount= amount) bid_action="Created" else: bid.bid_amount = amount bid.save(update_fields=['bid_amount']) bid_action="Modified" #function for notifying bidders notify(item= item_name, username= bidder, bid_amount= amount) return ("{0} Bid: {1} {2}".format(bid_action,bid.item.item_name, bid.bid_amount))
def add_bid(request): bidder, item_name, amount = read_request_item(request) item = Items.objects.get(item_name=item_name) if is_sold(item): return ("Cannot Bid: {0}. Item already sold".format(item_name)) else: try: bid = bids.objects.get(item=item, bidder=bidder) except bids.DoesNotExist: bid = bids.objects.create(bidder=bidder, item=item, bid_amount=amount) bid_action = "Created" else: bid.bid_amount = amount bid.save(update_fields=['bid_amount']) bid_action = "Modified" #function for notifying bidders notify(item=item_name, username=bidder, bid_amount=amount) return ("{0} Bid: {1} {2}".format(bid_action, bid.item.item_name, bid.bid_amount))