Commit 38180071 authored by Felizia Tiburcio's avatar Felizia Tiburcio

Store Place Bid form input in database

parent 73813917
......@@ -74,26 +74,25 @@ a{% extends 'boodlesite\templates\base.html' %}
<div class="modal-body">
<form action="" method="POST">
<div class="form-group">
<h1>Current Highest Bid: PHP {{highest_bid.amount}}</h1>
<label for="recipient-name" class="col-form-label">Enter Bid amount:</label>
{% csrf_token %}
{{ form }}
<input type="number" class="form-control" id="amount">
<!--add an if else statement here re. floor price-->
{% for bid in auction_bids %}
{% if bid.amount > item_floor_price %}
<!--How to make it post the bid and end up in data base and page-->
{% else %}
<h4>Please enter a price greater than the item's floor price</h4>
{% endif %}
{% if form.amount.errors %}
<ol>
{% for error in form.amount.errors %}
<li><strong>{{ error|escape }}</strong></li>
{% endfor %}
</ol>
{% endif %}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type = "submit" class="btn btn-secondary" name = "Submit"> Submit </button>
<button type="submit" class="btn btn-secondary" name="Submit"> Submit </button>
<!-- {% comment %} <button type="submit" class="btn btn-primary" value="Submit">Confirm Bid</button> {% endcomment %} -->
</div>
</form>
......@@ -108,7 +107,7 @@ a{% extends 'boodlesite\templates\base.html' %}
{% if auction_bids %}
{% for bid in auction_bids %}
<li><img src="" alt="">
<p>Alice offered {{ bid.amount }}</p>
<p>User offered {{ bid.amount }}</p>
<p>{{bid.bidtime | timesince}} ago </p>
</li>
......
......@@ -2,6 +2,9 @@ from django.shortcuts import render, redirect
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.core.exceptions import ValidationError
from .models import *
from .forms import *
......@@ -32,28 +35,37 @@ def homepage(request):
def auction(request, pk):
# Current auction ID
auction = Auction.objects.get(pk=pk)
auction_bids = AuctionBid.objects.filter(auctionid=pk)
# Item for auction
auction_item = auction.itemid
# Auction bids
auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime')
if not auction_bids:
highest_bid = auction_item.floorprice
else:
highest_bid = auction_bids[0]
form = PlaceBidForm()
# if this is a POST request we need to process the form data
if request.method == 'POST':
# create a form instance and populate it with data from the request:
print("Printing POST: ", request.POST)
form = PlaceBidForm(request.POST)
if form.is_valid():
amount = form.cleaned_data['amount']
if amount > highest_bid.amount:
new_bid = AuctionBid(amount=amount,bidtime=datetime.now(),auctionid=auction)
new_bid.save()
return redirect(f"/auction/{pk}")
else:
raise ValidationError("ERROR")
print(auction_bids)
print(type(auction_bids))
for bid in auction_bids:
print(bid.amount)
context = {
'item_name':auction_item.itemname,
'item_specs': auction_item.itemspecs,
'auction_bids' : auction_bids,
'item_floor_price': auction_item.floorprice,
'highest_bid':highest_bid,
'form' : form
# need to make floor price object here
}
if auction.auctionend < datetime.now():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment