add closed bid
This commit is contained in:
parent
0a27b0677b
commit
42e38c6c19
Binary file not shown.
Binary file not shown.
|
@ -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),
|
||||
),
|
||||
]
|
Binary file not shown.
|
@ -23,6 +23,7 @@ class AuctionListing(models.Model):
|
|||
picture = models.URLField(default="https://www.riobeauty.co.uk/images/product_image_not_found.gif")
|
||||
category = models.CharField(max_length = 64,choices=category_choices)
|
||||
date_added = models.DateTimeField(auto_now_add=True)
|
||||
closed = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
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):
|
||||
return '%s - %s - %s' % (self.bid_value, self.user, self.listing)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<h2>Active Listings</h2>
|
||||
<div class="row">
|
||||
{% 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;">
|
||||
<div class="card border-light" style="width: 18rem;">
|
||||
<div class="shadow p-2 mb-2 bg-white rounded">
|
||||
|
|
|
@ -9,39 +9,51 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1>Auctions</h1>
|
||||
<div style = "align-self: flex-end;">
|
||||
<div class = "text-right" style = "align-self: flex-end;">
|
||||
{% if user.is_authenticated %}
|
||||
Signed in as <strong>{{ user.username }}</strong>.
|
||||
{% else %}
|
||||
Not signed in.
|
||||
{% endif %}
|
||||
</div>
|
||||
<ul class="nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'index' %}">Active Listings</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'categories' %}">Categories</a>
|
||||
</li>
|
||||
{% if user.is_authenticated %}
|
||||
<nav class="navbar navbar-expand-md navbar-light bg-light">
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarNavDropdown">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="{% url 'index' %}">Active Listings <span class="sr-only">(current)</span></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'categories' %}">Categories</a>
|
||||
</li>
|
||||
{% if user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'watchlist' %}">WatchList <span class="badge badge-secondary">{{ user.watchlist.count }}</span></a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'create' %}">Create Listing</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'logout' %}">Log Out</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'login' %}">Log In</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'register' %}">Register</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
|
||||
{% if not user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'login'%}">Login</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'register' %}">Register</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'logout' %}">Logout</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
<hr>
|
||||
{% block body %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -25,15 +25,29 @@
|
|||
<img src = "{{Listing.picture}}" width = "50%" height= "50%"></img>
|
||||
<hr>
|
||||
|
||||
<p>{{Listing.desc}}</p>
|
||||
<p style="font-size: large;">{{Listing.desc}}</p>
|
||||
|
||||
|
||||
<h3>${{bids.bid_value}}</h3>
|
||||
bids so far
|
||||
{% if Listing.closed %}
|
||||
<br>
|
||||
<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 %}
|
||||
<form action="{% url 'bid' Listing.title %}" method = "POST">
|
||||
{% 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/>
|
||||
<input class="btn btn-primary" type="submit" value="Place Bid">
|
||||
|
@ -42,6 +56,7 @@
|
|||
<br>
|
||||
<strong>Log In to bid on this Listing</strong>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<br>
|
||||
<hr>
|
||||
<h4>Comments ...</h4>
|
||||
|
@ -54,7 +69,7 @@
|
|||
|
||||
{% else %}
|
||||
{% for comment in Listing.comments.all %}
|
||||
<strong>{{comment.user}} - {{comment.date_added}}</strong>
|
||||
<strong style="color:maroon;">{{comment.user}} - {{comment.date_added}}</strong>
|
||||
<br/>
|
||||
{{ comment.body }}
|
||||
<br/>
|
||||
|
@ -63,20 +78,25 @@
|
|||
|
||||
|
||||
{% endif %}
|
||||
{% if user.is_authenticated %}
|
||||
{% if not Listing.closed%}
|
||||
<h5>Add comment</h5>
|
||||
<p>
|
||||
<form method="POST">
|
||||
<form action="{% url 'listing' Listing.title %}" method="POST">
|
||||
{% 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>
|
||||
<input class="btn btn-primary" type="submit" value="Submit">
|
||||
</form>
|
||||
</p>
|
||||
{% elif not user.is_authenticated %}
|
||||
<br/>
|
||||
<hr>
|
||||
Log In to comment on this listing
|
||||
|
||||
{% else %}
|
||||
<br/>
|
||||
<hr>
|
||||
Log In to comment on this listing
|
||||
The Listing is <strong style="color:red;">CLOSED</strong> for comments
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
|
|
@ -164,6 +164,15 @@ def bid(request, title):
|
|||
"bids" : bid
|
||||
})
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Loading…
Reference in New Issue