Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Boodle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Martina Therese R. Reyes
Boodle
Commits
38180071
Commit
38180071
authored
Mar 27, 2022
by
Felizia Tiburcio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store Place Bid form input in database
parent
73813917
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
28 deletions
+39
-28
auction.html
boodlesite/templates/auction.html
+16
-17
forms.py
main/forms.py
+1
-1
views.py
main/views.py
+22
-10
No files found.
boodlesite/templates/auction.html
View file @
38180071
...
...
@@ -74,29 +74,28 @@ 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 %}
{% endfor %}
{% csrf_token %}
{{ form }}
<input
type=
"number"
class=
"form-control"
id=
"amount"
>
{% 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>
</div>
</form>
</div>
</div>
...
...
@@ -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>
...
...
main/forms.py
View file @
38180071
...
...
@@ -6,4 +6,4 @@ from .models import *
class
PlaceBidForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
AuctionBid
fields
=
[
'amount'
]
fields
=
[
'amount'
]
\ No newline at end of file
main/views.py
View file @
38180071
...
...
@@ -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
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment