diff --git a/auctions/__pycache__/views.cpython-37.pyc b/auctions/__pycache__/views.cpython-37.pyc index f6b5070..b61d468 100644 Binary files a/auctions/__pycache__/views.cpython-37.pyc and b/auctions/__pycache__/views.cpython-37.pyc differ diff --git a/auctions/templates/auctions/index.html b/auctions/templates/auctions/index.html index e369078..bb09930 100644 --- a/auctions/templates/auctions/index.html +++ b/auctions/templates/auctions/index.html @@ -14,18 +14,42 @@

{{ listing.title }}


- -

- bid price : ${{listing.price}}
+ {% if not listing.closed %} +

+ {% for bidding in listing.bidding_listing.all %} + bid price : ${{bidding.bid_value}}
+ Last bid by: {{bidding.user}} +
created by: {{listing.user}}
+ {% endfor %} created on {{listing.date_added}}

-
- -
+ {% else %} +

+ CLOSED +
+ This listing is over. +
+
+ {% for bidding in listing.bidding_listing.all %} + {% if user == bidding.user %} + You won this listing!!! + {% else %} + This is won by @{{ bidding.user }} + for ${{bidding.bid_value}} + {% endif %} + {% endfor %} + +

+ {% endif %} + +
- {% if user.is_authenticated %} + {% if listing.closed %} + + + {% elif user.is_authenticated %}
{% csrf_token %} diff --git a/auctions/templates/auctions/listing.html b/auctions/templates/auctions/listing.html index 7ee0945..213f617 100644 --- a/auctions/templates/auctions/listing.html +++ b/auctions/templates/auctions/listing.html @@ -36,23 +36,17 @@

${{bids.bid_value}} by @{{bids.user}}


- {% if user.is_authenticated %} + {% if user.is_authenticated and user != Listing.user %} {% csrf_token %} -
-
- $ -
- -
- .00 -
-
+ {{ bid_form }}
- {% else %} + {% elif user.is_authenticated and user == Listing.user%} +
You can't bid on your own Listing
+ {% else %}
Log In to bid on this Listing {% endif %} diff --git a/auctions/views.py b/auctions/views.py index a901427..7e00c75 100644 --- a/auctions/views.py +++ b/auctions/views.py @@ -1,4 +1,5 @@ from django.contrib.auth import authenticate, login, logout +from django.core.validators import MinValueValidator, MaxValueValidator from django.db import IntegrityError from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import render @@ -9,11 +10,12 @@ from .models import User,AuctionListing,Comment,Bids categories = ['Fashion','Electronics','Home','Sports','Toys','Automobile','Books','Videogames', 'Other'] class Bid_Form(forms.Form): - bid = 0.0 - def __init__(self,bid_value): - self.bid = bid_value - - bid_value = forms.DecimalField(decimal_places=2,min_value= bid + 1) + bid_value = 0.00 + def __init__(self, *args, **kwargs): + super(Bid_Form, self).__init__(*args, **kwargs) + self.fields['bid'].widget.attrs['min'] = 10 + + bid = forms.DecimalField(decimal_places=2) def watch(request,title): if request.method =="POST": @@ -46,7 +48,6 @@ def listing(request,title): """ listing = AuctionListing.objects.get(pk = title) bids = Bids.objects.get(listing = listing) - print(bids) if request.method == "POST": body = request.POST["comment_body"] comment = Comment(user=request.user,listing=listing,body = body) @@ -56,7 +57,8 @@ def listing(request,title): return render(request,"auctions/listing.html",{ "Listing": listing, - "bids" : bids + "bids" : bids, + "bid_form":Bid_Form(bids.bid_value) }) def category(request,cat_name = None): @@ -140,7 +142,7 @@ def create(request): starting_bid = request.POST["starting_bid"] photo_url = request.POST["photo"] if photo_url == "": - photo_url = "https://www.riobeauty.co.uk/images/product_image_not_found.gif" + photo_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/No_image_available_600_x_450.svg/1280px-No_image_available_600_x_450.svg.png" category = request.POST["category"] listing_obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url,category=category) listing_obj.save() @@ -161,7 +163,8 @@ def bid(request, title): bid.user = request.user return render(request,"auctions/listing.html",{ "Listing": listing, - "bids" : bid + "bids" : bid, + "bid_form":Bid_Form(bid.bid_value) }) def close_bid(request,title): listing = AuctionListing.objects.get(title=title) diff --git a/db.sqlite3 b/db.sqlite3 index 9c78f25..814ccbb 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ