bids improved
This commit is contained in:
parent
7943d031e8
commit
0a27b0677b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,8 +1,9 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import User
|
from .models import User
|
||||||
from .models import AuctionListing,Comment
|
from .models import AuctionListing,Comment,Bids
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
admin.site.register(User)
|
admin.site.register(User)
|
||||||
admin.site.register(AuctionListing)
|
admin.site.register(AuctionListing)
|
||||||
admin.site.register(Comment)
|
admin.site.register(Comment)
|
||||||
|
admin.site.register(Bids)
|
||||||
|
|
|
@ -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
|
from django.conf import settings
|
||||||
import django.contrib.auth.models
|
import django.contrib.auth.models
|
||||||
|
@ -49,15 +49,34 @@ class Migration(migrations.Migration):
|
||||||
('title', models.CharField(max_length=64, primary_key=True, serialize=False)),
|
('title', models.CharField(max_length=64, primary_key=True, serialize=False)),
|
||||||
('price', models.DecimalField(decimal_places=2, max_digits=10)),
|
('price', models.DecimalField(decimal_places=2, max_digits=10)),
|
||||||
('desc', models.CharField(max_length=1000)),
|
('desc', models.CharField(max_length=1000)),
|
||||||
('picture', models.URLField(null=True)),
|
('picture', models.URLField(default='https://www.riobeauty.co.uk/images/product_image_not_found.gif')),
|
||||||
('category', models.CharField(max_length=64)),
|
('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)),
|
('date_added', models.DateTimeField(auto_now_add=True)),
|
||||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
('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(
|
migrations.AddField(
|
||||||
model_name='user',
|
model_name='user',
|
||||||
name='watchlist',
|
name='watchlist',
|
||||||
field=models.ManyToManyField(blank=True, related_name='watchlist', to='auctions.AuctionListing'),
|
field=models.ManyToManyField(blank=True, related_name='watchlists', to='auctions.AuctionListing'),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -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',
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -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,
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -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)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -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),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -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),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -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)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -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'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -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),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -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),
|
|
||||||
),
|
|
||||||
]
|
|
Binary file not shown.
|
@ -40,4 +40,7 @@ class Bids(models.Model):
|
||||||
bid_value = models.DecimalField(max_digits = 10,decimal_places = 2)
|
bid_value = models.DecimalField(max_digits = 10,decimal_places = 2)
|
||||||
user = models.ForeignKey(User,on_delete = models.CASCADE, related_name="bidding_user")
|
user = models.ForeignKey(User,on_delete = models.CASCADE, related_name="bidding_user")
|
||||||
listing = models.ForeignKey(AuctionListing, on_delete= models.CASCADE, related_name="bidding_listing")
|
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)
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,14 @@
|
||||||
<div class = "text-right">
|
<div class = "text-right">
|
||||||
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<form action="{% url 'watchlist' list.title %}" method="POST">
|
<form action="{% url 'watch' list.title %}" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% if user not in list.watchlists.all %}
|
{% if user not in list.watchlists.all %}
|
||||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
|
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
|
||||||
{% else %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
<input type="hidden" name="previous" value="{{ request.path }}">
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<small>log in to watch this listing</small>
|
<small>log in to watch this listing</small>
|
||||||
|
|
|
@ -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-3">
|
<div class="col sm-2">
|
||||||
<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">
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
<b>bid price</b> : ${{listing.price}}<br>
|
<b>bid price</b> : ${{listing.price}}<br>
|
||||||
<b>created by</b>: {{listing.user}}<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>
|
</p>
|
||||||
<div class = "text-light">
|
<div class = "text-light">
|
||||||
|
|
||||||
|
@ -27,13 +27,15 @@
|
||||||
<div class = "text-right">
|
<div class = "text-right">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
|
|
||||||
<form action="{% url 'watchlist' listing.title %}" method="POST">
|
<form action="{% url 'watch' listing.title %}" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% if user not in listing.watchlists.all %}
|
{% if user not in listing.watchlists.all %}
|
||||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
|
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
|
||||||
{% else %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
|
<input type="hidden" name="previous" value="{{ request.path }}">
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<small>log in to watch this listing</small>
|
<small>log in to watch this listing</small>
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
</li>
|
</li>
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<li class="nav-item">
|
<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>
|
||||||
<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>
|
||||||
|
|
|
@ -3,39 +3,73 @@
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>Listing : {{ Listing.title}}</h2>
|
<h2>Listing : {{ Listing.title}}</h2>
|
||||||
|
|
||||||
|
<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 = "100%" height= "100%"></img>
|
<img src = "{{Listing.picture}}" width = "50%" height= "50%"></img>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p>{{Listing.desc}}</p>
|
<p>{{Listing.desc}}</p>
|
||||||
|
|
||||||
|
|
||||||
<h3>${{Listing.price}}</h3>
|
<h3>${{bids.bid_value}}</h3>
|
||||||
bids so far
|
bids so far
|
||||||
<div class="form-group">
|
{% if user.is_authenticated %}
|
||||||
<input class="form-control" autofocus type="number" name="bid" placeholder="Bid">
|
<form action="{% url 'bid' Listing.title %}" method = "POST">
|
||||||
</div>
|
{% csrf_token %}
|
||||||
<input class="btn btn-primary" type="submit" value="Place Bid">
|
<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>
|
<h4>Comments ...</h4>
|
||||||
|
|
||||||
{% if not Listing.comments.all %}
|
{% if not Listing.comments.all %}
|
||||||
No comments Yet....
|
No comments Yet....
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
{% for comment in Listing.comments.all %}
|
{% for comment in Listing.comments.all %}
|
||||||
<strong>{{comment.user}} - {{comment.date_added}}</strong>
|
<strong>{{comment.user}} - {{comment.date_added}}</strong>
|
||||||
<br/>
|
<br/>
|
||||||
{{ comment.body }}
|
{{ comment.body }}
|
||||||
<br/>
|
<br/>
|
||||||
|
<hr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<h5>add comment..</h5>
|
<h5>Add comment</h5>
|
||||||
<p>
|
<p>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input class = "form-control" name="comment_body" autofocus type="text" rows=4 cols= 50 placeholder="Comment here!">
|
<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">
|
<input class="btn btn-primary" type="submit" value="Submit">
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
|
@ -45,4 +79,7 @@
|
||||||
Log In to comment on this listing
|
Log In to comment on this listing
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>WatchList </h2>
|
<h2>WatchList </h2>
|
||||||
|
{% if Watchlistings %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
{% for listing in Watchlistings %}
|
{% for listing in Watchlistings %}
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
|
@ -22,13 +23,15 @@
|
||||||
<small><i> created at {{listing.date_added}}</i> </small>
|
<small><i> created at {{listing.date_added}}</i> </small>
|
||||||
</p>
|
</p>
|
||||||
<div class = "text-right">
|
<div class = "text-right">
|
||||||
<form action = "{% url 'watchlist' listing.title %}" method="POST">
|
<form action = "{% url 'watch' listing.title %}" method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% if user not in listing.watchlists.all %}
|
{% if user not in listing.watchlists.all %}
|
||||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
|
<button type="submit" name="watch", value="{{user}}", class="btn btn-primary btn-sm">Watch</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary btn-sm">Unwatch</button>
|
<button type="submit" name="watch", value="{{user}}", class="btn btn-secondary btn-sm">Unwatch</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<input type="hidden" name="previous" value="{{ request.path }}">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,5 +45,9 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<center><h3>There seems to be no listing you are watching !!
|
||||||
|
</h3></center>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -7,11 +7,13 @@ urlpatterns = [
|
||||||
path("login", views.login_view, name="login"),
|
path("login", views.login_view, name="login"),
|
||||||
path("logout", views.logout_view, name="logout"),
|
path("logout", views.logout_view, name="logout"),
|
||||||
path("register", views.register, name="register"),
|
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("create", views.create, name="create"),
|
||||||
path("categories", views.category, name="categories"),
|
path("categories", views.category, name="categories"),
|
||||||
path("category/<str:cat_name>",views.category,name="individual_categories"),
|
path("category/<str:cat_name>",views.category,name="individual_categories"),
|
||||||
path("listing/<str:title>",views.listing,name="listing"),
|
path("listing/<str:title>",views.listing,name="listing"),
|
||||||
path("category/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"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -4,7 +4,7 @@ from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django import forms
|
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']
|
categories = ['Fashion','Electronics','Home','Sports','Toys','Automobile','Books','Videogames', 'Other']
|
||||||
|
@ -22,7 +22,9 @@ def watch(request,title):
|
||||||
request.user.watchlist.remove(listing)
|
request.user.watchlist.remove(listing)
|
||||||
else:
|
else:
|
||||||
request.user.watchlist.add(listing)
|
request.user.watchlist.add(listing)
|
||||||
return HttpResponseRedirect(reverse("index"))
|
previous_url = request.POST.get('previous','/')
|
||||||
|
|
||||||
|
return HttpResponseRedirect(previous_url)
|
||||||
def watchlist(request):
|
def watchlist(request):
|
||||||
listings = request.user.watchlist.all()
|
listings = request.user.watchlist.all()
|
||||||
|
|
||||||
|
@ -42,14 +44,19 @@ def listing(request,title):
|
||||||
"""
|
"""
|
||||||
docstring
|
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":
|
if request.method == "POST":
|
||||||
body = request.POST["comment_body"]
|
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()
|
comment.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return render(request,"auctions/listing.html",{
|
return render(request,"auctions/listing.html",{
|
||||||
"Listing": listings
|
"Listing": listing,
|
||||||
|
"bids" : bids
|
||||||
})
|
})
|
||||||
|
|
||||||
def category(request,cat_name = None):
|
def category(request,cat_name = None):
|
||||||
|
@ -132,11 +139,13 @@ def create(request):
|
||||||
desc = request.POST["desc"]
|
desc = request.POST["desc"]
|
||||||
starting_bid = request.POST["starting_bid"]
|
starting_bid = request.POST["starting_bid"]
|
||||||
photo_url = request.POST["photo"]
|
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"
|
photo_url = "https://www.riobeauty.co.uk/images/product_image_not_found.gif"
|
||||||
category = request.POST["category"]
|
category = request.POST["category"]
|
||||||
obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url,category=category)
|
listing_obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url,category=category)
|
||||||
obj.save()
|
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",{
|
return render(request,"auctions/index.html",{
|
||||||
"Listings" : AuctionListing.objects.all()
|
"Listings" : AuctionListing.objects.all()
|
||||||
})
|
})
|
||||||
|
@ -144,6 +153,17 @@ def create(request):
|
||||||
return render(request,"auctions/create_listing.html",{
|
return render(request,"auctions/create_listing.html",{
|
||||||
"categories":categories
|
"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
|
||||||
|
|
||||||
|
|
||||||
|
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Loading…
Reference in New Issue