bids improved

This commit is contained in:
Priyatham-sai-chand 2020-10-20 22:41:58 +05:30
parent 7943d031e8
commit 0a27b0677b
25 changed files with 123 additions and 231 deletions

View File

@ -1,8 +1,9 @@
from django.contrib import admin
from .models import User
from .models import AuctionListing,Comment
from .models import AuctionListing,Comment,Bids
# Register your models here.
admin.site.register(User)
admin.site.register(AuctionListing)
admin.site.register(Comment)
admin.site.register(Bids)

View File

@ -1,4 +1,4 @@
# Generated by Django 3.0.8 on 2020-10-18 16:09
# Generated by Django 3.0.8 on 2020-10-19 17:27
from django.conf import settings
import django.contrib.auth.models
@ -49,15 +49,34 @@ class Migration(migrations.Migration):
('title', models.CharField(max_length=64, primary_key=True, serialize=False)),
('price', models.DecimalField(decimal_places=2, max_digits=10)),
('desc', models.CharField(max_length=1000)),
('picture', models.URLField(null=True)),
('category', models.CharField(max_length=64)),
('picture', models.URLField(default='https://www.riobeauty.co.uk/images/product_image_not_found.gif')),
('category', models.CharField(choices=[('Fashion', 'Fashion'), ('Electronics', 'Electronics'), ('Home', 'Home'), ('Sports', 'Sports'), ('Toys', 'Toys'), ('Automobile', 'Automobile'), ('Books', 'Books'), ('Videogames', 'Videogames'), ('Other', 'Other')], max_length=64)),
('date_added', models.DateTimeField(auto_now_add=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('date_added', models.DateTimeField(auto_now_add=True)),
('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='auctions.AuctionListing')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commited_user', to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Bids',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('bid_value', models.DecimalField(decimal_places=2, max_digits=10)),
('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bidding_listing', to='auctions.AuctionListing')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bidding_user', to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='user',
name='watchlist',
field=models.ManyToManyField(blank=True, related_name='watchlist', to='auctions.AuctionListing'),
field=models.ManyToManyField(blank=True, related_name='watchlists', to='auctions.AuctionListing'),
),
]

View File

@ -1,17 +0,0 @@
# Generated by Django 3.0.8 on 2020-10-18 16:16
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('auctions', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='auctionlisting',
name='date_added',
),
]

View File

@ -1,20 +0,0 @@
# Generated by Django 3.0.8 on 2020-10-18 16:18
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('auctions', '0002_remove_auctionlisting_date_added'),
]
operations = [
migrations.AddField(
model_name='auctionlisting',
name='date_added',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
]

View File

@ -1,25 +0,0 @@
# Generated by Django 3.0.8 on 2020-10-18 16:42
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('auctions', '0003_auctionlisting_date_added'),
]
operations = [
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField()),
('date_added', models.DateTimeField(auto_now_add=True)),
('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='auctions.AuctionListing')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commited_user', to=settings.AUTH_USER_MODEL)),
],
),
]

View File

@ -1,23 +0,0 @@
# Generated by Django 3.0.8 on 2020-10-18 17:34
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auctions', '0004_comment'),
]
operations = [
migrations.RemoveField(
model_name='user',
name='watchlist',
),
migrations.AddField(
model_name='auctionlisting',
name='watchlist',
field=models.ManyToManyField(blank=True, related_name='watchlist', to=settings.AUTH_USER_MODEL),
),
]

View File

@ -1,27 +0,0 @@
# Generated by Django 3.0.8 on 2020-10-19 05:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auctions', '0005_auto_20201018_2304'),
]
operations = [
migrations.RemoveField(
model_name='auctionlisting',
name='watchlist',
),
migrations.AddField(
model_name='user',
name='watchlist',
field=models.ManyToManyField(blank=True, related_name='watchlist', to='auctions.AuctionListing'),
),
migrations.AlterField(
model_name='auctionlisting',
name='category',
field=models.CharField(choices=[('Fashion', 'Fashion'), ('Electronics', 'Electronics'), ('Home', 'Home'), ('Sports', 'Sports'), ('Toys', 'Toys'), ('Automobile', 'Automobile'), ('Books', 'Books'), ('Video Games', 'Video Games'), ('Other', 'Other')], max_length=64),
),
]

View File

@ -1,34 +0,0 @@
# Generated by Django 3.0.8 on 2020-10-19 11:53
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('auctions', '0006_auto_20201019_1109'),
]
operations = [
migrations.AlterField(
model_name='auctionlisting',
name='picture',
field=models.URLField(default='https://www.riobeauty.co.uk/images/product_image_not_found.gif', null=True),
),
migrations.AlterField(
model_name='user',
name='watchlist',
field=models.ManyToManyField(blank=True, related_name='watchlists', to='auctions.AuctionListing'),
),
migrations.CreateModel(
name='Bids',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('bid_value', models.DecimalField(decimal_places=2, max_digits=10)),
('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bidding_listing', to='auctions.AuctionListing')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='bidding_user', to=settings.AUTH_USER_MODEL)),
],
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 3.0.8 on 2020-10-19 11:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auctions', '0007_auto_20201019_1723'),
]
operations = [
migrations.AlterField(
model_name='auctionlisting',
name='picture',
field=models.URLField(default='https://www.riobeauty.co.uk/images/product_image_not_found.gif'),
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 3.0.8 on 2020-10-19 12:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auctions', '0008_auto_20201019_1725'),
]
operations = [
migrations.AlterField(
model_name='auctionlisting',
name='category',
field=models.CharField(choices=[('Fashion', 'Fashion'), ('Electronics', 'Electronics'), ('Home', 'Home'), ('Sports', 'Sports'), ('Toys', 'Toys'), ('Automobile', 'Automobile'), ('Books', 'Books'), ('Video-Games', 'Video-Games'), ('Other', 'Other')], max_length=64),
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 3.0.8 on 2020-10-19 12:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auctions', '0009_auto_20201019_1740'),
]
operations = [
migrations.AlterField(
model_name='auctionlisting',
name='category',
field=models.CharField(choices=[('Fashion', 'Fashion'), ('Electronics', 'Electronics'), ('Home', 'Home'), ('Sports', 'Sports'), ('Toys', 'Toys'), ('Automobile', 'Automobile'), ('Books', 'Books'), ('Videogames', 'Videogames'), ('Other', 'Other')], max_length=64),
),
]

View File

@ -41,3 +41,6 @@ class Bids(models.Model):
user = models.ForeignKey(User,on_delete = models.CASCADE, related_name="bidding_user")
listing = models.ForeignKey(AuctionListing, on_delete= models.CASCADE, related_name="bidding_listing")
def __str__(self):
return '%s - %s - %s' % (self.bid_value, self.user, self.listing)

View File

@ -24,13 +24,14 @@
<div class = "text-right">
{% if user.is_authenticated %}
<form action="{% url 'watchlist' list.title %}" method="POST">
<form action="{% url 'watch' list.title %}" method="POST">
{% csrf_token %}
{% if user not in list.watchlists.all %}
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
{% else %}
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Unwatch</button>
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary btn-sm">Unwatch</button>
{% endif %}
<input type="hidden" name="previous" value="{{ request.path }}">
</form>
{% else %}
<small>log in to watch this listing</small>

View File

@ -4,7 +4,7 @@
<h2>Active Listings</h2>
<div class="row">
{% for listing in Listings %}
<div class="col-sm-3">
<div class="col sm-2">
<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">
@ -19,7 +19,7 @@
<b>bid price</b> : ${{listing.price}}<br>
<b>created by</b>: {{listing.user}}<br>
<small><i> created at {{listing.date_added}}</i> </small>
<small class="text-muted"><i> created on {{listing.date_added}}</i> </small>
</p>
<div class = "text-light">
@ -27,13 +27,15 @@
<div class = "text-right">
{% if user.is_authenticated %}
<form action="{% url 'watchlist' listing.title %}" method="POST">
<form action="{% url 'watch' listing.title %}" method="POST">
{% csrf_token %}
{% if user not in listing.watchlists.all %}
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
{% else %}
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Unwatch</button>
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary btn-sm">Unwatch</button>
{% endif %}
<input type="hidden" name="previous" value="{{ request.path }}">
</form>
{% else %}
<small>log in to watch this listing</small>

View File

@ -25,7 +25,7 @@
</li>
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'wishlist' %}">WishList <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 class="nav-item">
<a class="nav-link" href="{% url 'create' %}">Create Listing</a>

View File

@ -4,38 +4,72 @@
{% block body %}
<h2>Listing : {{ Listing.title}}</h2>
<img src = "{{Listing.picture}}" width = "100%" height= "100%"></img>
<div class="text-right">
{% if user.username|stringformat:"s" == Listing.user|stringformat:"s" %}
<a class="btn btn-danger" href="{% url 'close_bid' Listing.title %}" role="button" style="display:inline;">Close this Listing</a>
{% endif %}
<form action="{% url 'watch' Listing.title %}" method="POST" style="display:inline;" >
{% csrf_token %}
{% if user not in Listing.watchlists.all %}
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary" >Watch</button>
{% else %}
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary">Unwatch</button>
{% endif %}
<input type="hidden" name="previous" value="{{ request.path }}">
</form>
</div>
<img src = "{{Listing.picture}}" width = "50%" height= "50%"></img>
<hr>
<p>{{Listing.desc}}</p>
<h3>${{Listing.price}}</h3>
<h3>${{bids.bid_value}}</h3>
bids so far
<div class="form-group">
<input class="form-control" autofocus type="number" name="bid" placeholder="Bid">
</div>
{% 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">
<br/>
<input class="btn btn-primary" type="submit" value="Place Bid">
</form>
{% else %}
<br>
<strong>Log In to bid on this Listing</strong>
{% endif %}
<br>
<hr>
<h4>Comments ...</h4>
{% if not Listing.comments.all %}
No comments Yet....
<br>
<br>
<br>
{% else %}
{% for comment in Listing.comments.all %}
<strong>{{comment.user}} - {{comment.date_added}}</strong>
<br/>
{{ comment.body }}
<br/>
<hr>
{% endfor %}
{% endif %}
{% if user.is_authenticated %}
<h5>add comment..</h5>
<h5>Add comment</h5>
<p>
<form method="POST">
{% csrf_token %}
<input class = "form-control" name="comment_body" autofocus type="text" rows=4 cols= 50 placeholder="Comment here!">
<br>
<input class="btn btn-primary" type="submit" value="Submit">
</form>
</p>
@ -45,4 +79,7 @@
Log In to comment on this listing
{% endif %}
{% endblock %}

View File

@ -2,6 +2,7 @@
{% block body %}
<h2>WatchList </h2>
{% if Watchlistings %}
<div class="row">
{% for listing in Watchlistings %}
<div class="col-sm-3">
@ -22,13 +23,15 @@
<small><i> created at {{listing.date_added}}</i> </small>
</p>
<div class = "text-right">
<form action = "{% url 'watchlist' listing.title %}" method="POST">
<form action = "{% url 'watch' listing.title %}" method="POST">
{% csrf_token %}
{% if user not in listing.watchlists.all %}
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
{% else %}
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary btn-sm">Unwatch</button>
{% endif %}
<input type="hidden" name="previous" value="{{ request.path }}">
</form>
@ -42,5 +45,9 @@
</div>
{% endfor %}
</div>
{% else %}
<center><h3>There seems to be no listing you are watching !!
</h3></center>
{% endif %}
{% endblock %}

View File

@ -7,11 +7,13 @@ urlpatterns = [
path("login", views.login_view, name="login"),
path("logout", views.logout_view, name="logout"),
path("register", views.register, name="register"),
path("watchlist", views.watchlist, name="wishlist"),
path("watchlist", views.watchlist, name="watchlist"),
path("create", views.create, name="create"),
path("categories", views.category, name="categories"),
path("category/<str:cat_name>",views.category,name="individual_categories"),
path("listing/<str:title>",views.listing,name="listing"),
path("category/listing/<str:title>",views.listing,name="listing"),
path("watch/<str:title>",views.watch,name="watchlist"),
path("watch/<str:title>",views.watch,name="watch"),
path("bid/<str:title>",views.bid,name="bid"),
path("close/<str:title>",views.close_bid,name="close_bid"),
]

View File

@ -4,7 +4,7 @@ from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse
from django import forms
from .models import User,AuctionListing,Comment
from .models import User,AuctionListing,Comment,Bids
categories = ['Fashion','Electronics','Home','Sports','Toys','Automobile','Books','Videogames', 'Other']
@ -22,7 +22,9 @@ def watch(request,title):
request.user.watchlist.remove(listing)
else:
request.user.watchlist.add(listing)
return HttpResponseRedirect(reverse("index"))
previous_url = request.POST.get('previous','/')
return HttpResponseRedirect(previous_url)
def watchlist(request):
listings = request.user.watchlist.all()
@ -42,14 +44,19 @@ def listing(request,title):
"""
docstring
"""
listings = AuctionListing.objects.get(pk = 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=listings,body = body)
comment = Comment(user=request.user,listing=listing,body = body)
comment.save()
return render(request,"auctions/listing.html",{
"Listing": listings
"Listing": listing,
"bids" : bids
})
def category(request,cat_name = None):
@ -132,11 +139,13 @@ def create(request):
desc = request.POST["desc"]
starting_bid = request.POST["starting_bid"]
photo_url = request.POST["photo"]
if photo_url == None:
if photo_url == "":
photo_url = "https://www.riobeauty.co.uk/images/product_image_not_found.gif"
category = request.POST["category"]
obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url,category=category)
obj.save()
listing_obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url,category=category)
listing_obj.save()
bid_obj = Bids(bid_value = starting_bid, listing = listing_obj, user = request.user)
bid_obj.save()
return render(request,"auctions/index.html",{
"Listings" : AuctionListing.objects.all()
})
@ -144,6 +153,17 @@ def create(request):
return render(request,"auctions/create_listing.html",{
"categories":categories
})
def bid(request, title):
listing = AuctionListing.objects.get(title=title)
bid = Bids.objects.get(listing = listing)
new_bid_value = request.POST["bid"]
bid.bid_value = new_bid_value
bid.user = request.user
return render(request,"auctions/listing.html",{
"Listing": listing,
"bids" : bid
})
def close_bid(request,title):
pass

Binary file not shown.