close bid improved

This commit is contained in:
Priyatham-sai-chand 2020-10-22 23:05:00 +05:30
parent 42e38c6c19
commit 083fcf7b38
5 changed files with 48 additions and 27 deletions

View File

@ -14,18 +14,42 @@
<div class="card-body">
<h4>{{ listing.title }}</h4><br>
<p class="card-text" style="font-size: large;">
<b>bid price</b> : ${{listing.price}}<br>
{% if not listing.closed %}
<p class="card-text" style="font-size: medium;">
{% for bidding in listing.bidding_listing.all %}
<b>bid price</b> : ${{bidding.bid_value}}<br>
<b>Last bid by</b>: {{bidding.user}}
<br>
<b>created by</b>: {{listing.user}}<br>
{% endfor %}
<small class="text-muted"><i> created on {{listing.date_added}}</i> </small>
</p>
<div class = "text-light">
</div>
{% else %}
<p class="card-text" style="font-size: medium;">
<strong style="color:red;">CLOSED</strong>
<br>
This listing is over.
<br>
<br>
{% for bidding in listing.bidding_listing.all %}
{% if user == bidding.user %}
<b>You won this listing!!!</b>
{% else %}
<b>This is won by <strong style="color:navy;font-size: large;">@{{ bidding.user }}</strong></b>
for <strong>${{bidding.bid_value}}</strong>
{% endif %}
{% endfor %}
</p>
{% endif %}
<div class = "text-right">
{% if user.is_authenticated %}
{% if listing.closed %}
{% elif user.is_authenticated %}
<form action="{% url 'watch' listing.title %}" method="POST">
{% csrf_token %}

View File

@ -36,23 +36,17 @@
<h3 style="color:darkgreen;">${{bids.bid_value}} <small style = "color:black;">by</small> <small style="color:navy;">@{{bids.user}}</small></h3>
<br>
{% if user.is_authenticated %}
{% if user.is_authenticated and user != Listing.user %}
<form action="{% url 'bid' Listing.title %}" method = "POST">
{% csrf_token %}
<div class="input-group mb-2">
<div class="input-group-prepend">
<span class="input-group-text">$</span>
</div>
<input type="number" name="bid" class="form-control input-sm" aria-label="Amount (to the nearest dollar)" placeholder="Bid a dollar more than price" required="required" min={{bids.bid_value}} step="0.01">
<div class="input-group-append">
<span class="input-group-text">.00</span>
</div>
</div>
{{ bid_form }}
<br/>
<input class="btn btn-primary" type="submit" value="Place Bid">
</form>
{% else %}
{% elif user.is_authenticated and user == Listing.user%}
<h5>You can't bid on your own Listing</h5>
{% else %}
<br>
<strong>Log In to bid on this Listing</strong>
{% endif %}

View File

@ -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)

Binary file not shown.