add closed bid

This commit is contained in:
Priyatham-sai-chand 2020-10-21 21:29:14 +05:30
parent 0a27b0677b
commit 42e38c6c19
10 changed files with 93 additions and 34 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.8 on 2020-10-21 11:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auctions', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='auctionlisting',
name='closed',
field=models.BooleanField(default=False),
),
]

View File

@ -23,6 +23,7 @@ class AuctionListing(models.Model):
picture = models.URLField(default="https://www.riobeauty.co.uk/images/product_image_not_found.gif") picture = models.URLField(default="https://www.riobeauty.co.uk/images/product_image_not_found.gif")
category = models.CharField(max_length = 64,choices=category_choices) category = models.CharField(max_length = 64,choices=category_choices)
date_added = models.DateTimeField(auto_now_add=True) date_added = models.DateTimeField(auto_now_add=True)
closed = models.BooleanField(default=False)
def __str__(self): def __str__(self):
return f"{self.title}: {self.price},{self.desc},{self.picture},{self.category},{self.date_added}" return f"{self.title}: {self.price},{self.desc},{self.picture},{self.category},{self.date_added}"
@ -43,4 +44,3 @@ class Bids(models.Model):
def __str__(self): def __str__(self):
return '%s - %s - %s' % (self.bid_value, self.user, self.listing) return '%s - %s - %s' % (self.bid_value, self.user, self.listing)

View File

@ -4,7 +4,7 @@
<h2>Active Listings</h2> <h2>Active Listings</h2>
<div class="row"> <div class="row">
{% for listing in Listings %} {% for listing in Listings %}
<div class="col sm-2"> <div class="col-lg-3 mb-10">
<a href="listing/{{ listing.title}}" style = "color:inherit;text-decoration: none;"> <a href="listing/{{ listing.title}}" style = "color:inherit;text-decoration: none;">
<div class="card border-light" style="width: 18rem;"> <div class="card border-light" style="width: 18rem;">
<div class="shadow p-2 mb-2 bg-white rounded"> <div class="shadow p-2 mb-2 bg-white rounded">

View File

@ -9,39 +9,51 @@
</head> </head>
<body> <body>
<h1>Auctions</h1> <h1>Auctions</h1>
<div style = "align-self: flex-end;"> <div class = "text-right" style = "align-self: flex-end;">
{% if user.is_authenticated %} {% if user.is_authenticated %}
Signed in as <strong>{{ user.username }}</strong>. Signed in as <strong>{{ user.username }}</strong>.
{% else %} {% else %}
Not signed in. Not signed in.
{% endif %} {% endif %}
</div> </div>
<ul class="nav"> <nav class="navbar navbar-expand-md navbar-light bg-light">
<li class="nav-item">
<a class="nav-link" href="{% url 'index' %}">Active Listings</a> <div class="collapse navbar-collapse" id="navbarNavDropdown">
</li> <ul class="navbar-nav mr-auto">
<li class="nav-item"> <li class="nav-item active">
<a class="nav-link" href="{% url 'categories' %}">Categories</a> <a class="nav-link" href="{% url 'index' %}">Active Listings <span class="sr-only">(current)</span></a>
</li> </li>
{% if user.is_authenticated %} <li class="nav-item">
<a class="nav-link" href="{% url 'categories' %}">Categories</a>
</li>
{% if user.is_authenticated %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'watchlist' %}">WatchList <span class="badge badge-secondary">{{ user.watchlist.count }}</span></a> <a class="nav-link" href="{% url 'watchlist' %}">WatchList <span class="badge badge-secondary">{{ user.watchlist.count }}</span></a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'create' %}">Create Listing</a> <a class="nav-link" href="{% url 'create' %}">Create Listing</a>
</li> </li>
<li class="nav-item"> {% endif %}
<a class="nav-link" href="{% url 'logout' %}">Log Out</a> </ul>
</li> <ul class="navbar-nav">
{% else %}
<li class="nav-item"> {% if not user.is_authenticated %}
<a class="nav-link" href="{% url 'login' %}">Log In</a> <li class="nav-item">
</li> <a class="nav-link" href="{% url 'login'%}">Login</a>
<li class="nav-item"> </li>
<a class="nav-link" href="{% url 'register' %}">Register</a> <li class="nav-item">
</li> <a class="nav-link" href="{% url 'register' %}">Register</a>
{% endif %} </li>
</ul> {% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Logout</a>
</li>
{% endif %}
</ul>
</div>
</nav>
<hr> <hr>
{% block body %} {% block body %}
{% endblock %} {% endblock %}

View File

@ -25,15 +25,29 @@
<img src = "{{Listing.picture}}" width = "50%" height= "50%"></img> <img src = "{{Listing.picture}}" width = "50%" height= "50%"></img>
<hr> <hr>
<p>{{Listing.desc}}</p> <p style="font-size: large;">{{Listing.desc}}</p>
{% if Listing.closed %}
<h3>${{bids.bid_value}}</h3> <br>
bids so far <h3 style="background-color:orangered;color:white;"><center>This listing is CLOSED</center></h3>
<br>
<h4>This Listing is won by <strong style="color:maroon;">@{{bids.user}}</strong> for <strong style="color:green;">${{bids.bid_value}}</strong></h4>
{% else %}
<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 %}
<form action="{% url 'bid' Listing.title %}" method = "POST"> <form action="{% url 'bid' Listing.title %}" method = "POST">
{% csrf_token %} {% csrf_token %}
<input class="form-control" autofocus type="number" name="bid" placeholder="Bid" required="required" step="0.01"> <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>
<br/> <br/>
<input class="btn btn-primary" type="submit" value="Place Bid"> <input class="btn btn-primary" type="submit" value="Place Bid">
@ -42,6 +56,7 @@
<br> <br>
<strong>Log In to bid on this Listing</strong> <strong>Log In to bid on this Listing</strong>
{% endif %} {% endif %}
{% endif %}
<br> <br>
<hr> <hr>
<h4>Comments ...</h4> <h4>Comments ...</h4>
@ -54,7 +69,7 @@
{% else %} {% else %}
{% for comment in Listing.comments.all %} {% for comment in Listing.comments.all %}
<strong>{{comment.user}} - {{comment.date_added}}</strong> <strong style="color:maroon;">{{comment.user}} - {{comment.date_added}}</strong>
<br/> <br/>
{{ comment.body }} {{ comment.body }}
<br/> <br/>
@ -63,20 +78,25 @@
{% endif %} {% endif %}
{% if user.is_authenticated %} {% if not Listing.closed%}
<h5>Add comment</h5> <h5>Add comment</h5>
<p> <p>
<form method="POST"> <form action="{% url 'listing' Listing.title %}" method="POST">
{% csrf_token %} {% csrf_token %}
<input class = "form-control" name="comment_body" autofocus type="text" rows=4 cols= 50 placeholder="Comment here!"> <textarea class = "form-control" name="comment_body" rows="4" cols="50" placeholder="Comment here!"></textarea>
<br> <br>
<input class="btn btn-primary" type="submit" value="Submit"> <input class="btn btn-primary" type="submit" value="Submit">
</form> </form>
</p> </p>
{% elif not user.is_authenticated %}
<br/>
<hr>
Log In to comment on this listing
{% else %} {% else %}
<br/> <br/>
<hr> <hr>
Log In to comment on this listing The Listing is <strong style="color:red;">CLOSED</strong> for comments
{% endif %} {% endif %}

View File

@ -164,6 +164,15 @@ def bid(request, title):
"bids" : bid "bids" : bid
}) })
def close_bid(request,title): def close_bid(request,title):
pass listing = AuctionListing.objects.get(title=title)
listing.closed = True
listing.save()
previous_url = request.POST.get('previous','/')
print(previous_url)
return HttpResponseRedirect(previous_url)

Binary file not shown.