samedi 22 août 2020

if block not working in django view of python

def listingpage(request,title):   
    listings = Auctionlisting.objects.get(title=title)
    if request.method == "POST":
        form = Bidform(request.POST)
        if form.is_valid():
            bidmade = request.POST.get('bidmade')
            user = request.POST.get('username')
            username = User.objects.get(username=user)
            bid = Bid(user=username,bidmade=bidmade,bidobject=listings)
            if Bid.user != username and Bid.bidobject != listings:
                 bid.save()
                 return render(request, "auctions/listingpage.html",{
                 "listings":listings,
                 "bidform":form,
                 "message":"Your bid has been added in the auction..."
                 })
            
            else:
                return render(request,"auctions/error.html")
    else:
        form = Bidform()
    return render(request, "auctions/listingpage.html",{
    "listings":listings,
    "bidform":form
    })

can anybody tell me what is wrong with this code. if code is not working, it keeps on adding the bid even when it username and listing is already present in the bid database. i am using this code, in order to prevent more than once to place a bid on an object by a single username.

Aucun commentaire:

Enregistrer un commentaire