def FormEditBid(request, bid_id): bid = get_object_or_404(Bid, pk=bid_id) form = BidForm(request.POST or None, instance=bid) if form.is_valid(): bid = form.save() # this is where you might choose to do stuff. # contact.name = 'test' bid.save() return redirect(FormBid) return render_to_response( "bids/formeditbid.html", {"bid_form": form, "bid_id": bid_id}, context_instance=RequestContext(request) )
def FormAddBid(request): # sticks in a POST or renders empty form form = BidForm(request.POST or None) if form.is_valid(): cmodel = form.save(commit=False) cmodel.User = request.user cmodel.Status = "A" # TODO check if there are enouf funds, Participation < 100 and competitive bid rate < 100 # TODO Set status also cmodel.save() return redirect(FormBid) return render_to_response("bids/formaddbid.html", {"bid_form": form}, context_instance=RequestContext(request))
def view_listing(request, book_id): # Grab the listing itself listing = get_object_or_404(Listing,pk=book_id) # grab the bidder bidder = request.user.seller # if the listing is over a week old, it's old old_threshold = timezone.now() - timedelta(weeks=3) # get all bids associated with this listing bids = Bid.objects.filter( listing = listing ) bid_count = len(bids) bid_form = BidForm() if request.method == 'POST' and listing.active and not listing.sold: if listing.active and not listing.sold: bid_form = BidForm( request.POST.copy() ) # Override whatever the user may have input into the bidder and # listing fields (hopefully they will not have set these values # anyway). bid_form.data['bidder'] = bidder.pk bid_form.data['listing'] = listing.pk if bid_form.is_valid(): bid = bid_form.save(commit=False) bid.bidder = bidder bid.listing = listing bid.full_clean() bid.save() return redirect( 'view_listing', listing.pk ) return render(request, 'listing.html', { 'listing' : listing, 'media' : settings.MEDIA_URL, 'old' : listing.date_created < old_threshold, 'bid_count' : bid_count, 'bids' : bids, 'bid_form' : bid_form, }, )