Commit 38180071 authored by Felizia Tiburcio's avatar Felizia Tiburcio

Store Place Bid form input in database

parent 73813917
...@@ -74,29 +74,28 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -74,29 +74,28 @@ a{% extends 'boodlesite\templates\base.html' %}
<div class="modal-body"> <div class="modal-body">
<form action="" method="POST"> <form action="" method="POST">
<div class="form-group"> <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> <label for="recipient-name" class="col-form-label">Enter Bid amount:</label>
{% csrf_token %} {% csrf_token %}
{{ form }} {{ form }}
<input type="number" class="form-control" id="amount">
<input type="number" class="form-control" id="amount"> {% if form.amount.errors %}
<!--add an if else statement here re. floor price--> <ol>
{% for bid in auction_bids %} {% for error in form.amount.errors %}
{% if bid.amount > item_floor_price %} <li><strong>{{ error|escape }}</strong></li>
<!--How to make it post the bid and end up in data base and page--> {% endfor %}
</ol>
{% else %} {% endif %}
<h4>Please enter a price greater than the item's floor price</h4>
{% endif %}
{% endfor %}
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> <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 %} --> <!-- {% comment %} <button type="submit" class="btn btn-primary" value="Submit">Confirm Bid</button> {% endcomment %} -->
</div> </div>
</form> </form>
</div> </div>
</div> </div>
...@@ -108,7 +107,7 @@ a{% extends 'boodlesite\templates\base.html' %} ...@@ -108,7 +107,7 @@ a{% extends 'boodlesite\templates\base.html' %}
{% if auction_bids %} {% if auction_bids %}
{% for bid in auction_bids %} {% for bid in auction_bids %}
<li><img src="" alt=""> <li><img src="" alt="">
<p>Alice offered {{ bid.amount }}</p> <p>User offered {{ bid.amount }}</p>
<p>{{bid.bidtime | timesince}} ago </p> <p>{{bid.bidtime | timesince}} ago </p>
</li> </li>
......
...@@ -6,4 +6,4 @@ from .models import * ...@@ -6,4 +6,4 @@ from .models import *
class PlaceBidForm(forms.ModelForm): class PlaceBidForm(forms.ModelForm):
class Meta: class Meta:
model = AuctionBid model = AuctionBid
fields = ['amount'] fields = ['amount']
\ No newline at end of file
...@@ -2,6 +2,9 @@ from django.shortcuts import render, redirect ...@@ -2,6 +2,9 @@ from django.shortcuts import render, redirect
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.http import HttpResponse from django.http import HttpResponse
from django.core.exceptions import ValidationError
from .models import * from .models import *
from .forms import * from .forms import *
...@@ -32,28 +35,37 @@ def homepage(request): ...@@ -32,28 +35,37 @@ def homepage(request):
def auction(request, pk): def auction(request, pk):
# Current auction ID # Current auction ID
auction = Auction.objects.get(pk=pk) auction = Auction.objects.get(pk=pk)
auction_bids = AuctionBid.objects.filter(auctionid=pk) # Item for auction
auction_item = auction.itemid 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() form = PlaceBidForm()
# if this is a POST request we need to process the form data
if request.method == 'POST': if request.method == 'POST':
# create a form instance and populate it with data from the request: form = PlaceBidForm(request.POST)
print("Printing POST: ", 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 = { context = {
'item_name':auction_item.itemname, 'item_name':auction_item.itemname,
'item_specs': auction_item.itemspecs, 'item_specs': auction_item.itemspecs,
'auction_bids' : auction_bids, 'auction_bids' : auction_bids,
'item_floor_price': auction_item.floorprice, 'item_floor_price': auction_item.floorprice,
'highest_bid':highest_bid,
'form' : form 'form' : form
# need to make floor price object here
} }
if auction.auctionend < datetime.now(): 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