add watchlist
This commit is contained in:
parent
a25a71a7e2
commit
46cd6948dc
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,27 @@
|
||||||
|
# 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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,34 @@
|
||||||
|
# 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)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,18 @@
|
||||||
|
# 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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,18 @@
|
||||||
|
# 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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -0,0 +1,18 @@
|
||||||
|
# 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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -2,17 +2,27 @@ from django.contrib.auth.models import AbstractUser
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
class User(AbstractUser):
|
class User(AbstractUser):
|
||||||
pass
|
watchlist = models.ManyToManyField('AuctionListing',blank = True,related_name="watchlists")
|
||||||
|
|
||||||
class AuctionListing(models.Model):
|
class AuctionListing(models.Model):
|
||||||
|
category_choices = (
|
||||||
|
('Fashion','Fashion'),
|
||||||
|
('Electronics','Electronics'),
|
||||||
|
('Home','Home'),
|
||||||
|
('Sports','Sports'),
|
||||||
|
('Toys','Toys'),
|
||||||
|
('Automobile','Automobile'),
|
||||||
|
('Books','Books'),
|
||||||
|
('Videogames','Videogames'),
|
||||||
|
('Other','Other'),
|
||||||
|
)
|
||||||
title = models.CharField(max_length = 64,primary_key = True)
|
title = models.CharField(max_length = 64,primary_key = True)
|
||||||
user = models.ForeignKey(User,on_delete = models.CASCADE)
|
user = models.ForeignKey(User,on_delete = models.CASCADE)
|
||||||
price = models.DecimalField(max_digits = 10,decimal_places = 2)
|
price = models.DecimalField(max_digits = 10,decimal_places = 2)
|
||||||
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(max_length = 64,choices=category_choices)
|
||||||
date_added = models.DateTimeField(auto_now_add=True)
|
date_added = models.DateTimeField(auto_now_add=True)
|
||||||
watchlist = models.ManyToManyField(User,blank = True,related_name="watchlist")
|
|
||||||
|
|
||||||
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}"
|
||||||
|
@ -26,3 +36,8 @@ class Comment(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s - %s' % (self.listing.title, self.user)
|
return '%s - %s' % (self.listing.title, self.user)
|
||||||
|
class Bids(models.Model):
|
||||||
|
bid_value = models.DecimalField(max_digits = 10,decimal_places = 2)
|
||||||
|
user = models.ForeignKey(User,on_delete = models.CASCADE, related_name="bidding_user")
|
||||||
|
listing = models.ForeignKey(AuctionListing, on_delete= models.CASCADE, related_name="bidding_listing")
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
{% extends "auctions/layout.html"%}
|
{% extends "auctions/layout.html"%}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>Listings under category: {{ cat_name }}</h2>
|
<h2>Listings under category "{{ cat_name }}"</h2>
|
||||||
|
{% if listings %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
||||||
{% for list in listings %}
|
{% for list in listings %}
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<a href="listing/{{ list.title}}" style = "color:inherit;text-decoration: none;">
|
<a href="{% url 'listing' {{list.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">
|
||||||
<img class="card-img-top" src="{{ list.picture }}" alt="Preview not found">
|
<img class="card-img-top" src="{{ list.picture }}" alt="Preview not found">
|
||||||
|
@ -20,8 +22,19 @@
|
||||||
<b>created by</b>: {{list.user}}
|
<b>created by</b>: {{list.user}}
|
||||||
</p>
|
</p>
|
||||||
<div class = "text-right">
|
<div class = "text-right">
|
||||||
<input class="form-check-input" type="checkbox" value="" id="watch">
|
|
||||||
<label class="form-check-label" for="watch">Watch this item</label>
|
{% if user.is_authenticated %}
|
||||||
|
<form action="{% url 'watchlist' 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>
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<small>log in to watch this listing</small>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -33,4 +46,13 @@
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<center>
|
||||||
|
<h3> Seems to be no listings in this category</h3>
|
||||||
|
</center>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -21,12 +21,24 @@
|
||||||
|
|
||||||
<small><i> created at {{listing.date_added}}</i> </small>
|
<small><i> created at {{listing.date_added}}</i> </small>
|
||||||
</p>
|
</p>
|
||||||
|
<div class = "text-light">
|
||||||
|
|
||||||
|
</div>
|
||||||
<div class = "text-right">
|
<div class = "text-right">
|
||||||
<form action="{% url 'watch' request.user %}" method="POST">
|
{% if user.is_authenticated %}
|
||||||
{% csrf_token %}
|
|
||||||
<button type="submit" name="watch", value="{{listing.title}}", class="btn btn-primary btn-sm">Watch</button>
|
<form action="{% url 'watchlist' listing.title %}" method="POST">
|
||||||
</form>
|
{% 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>
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<small>log in to watch this listing</small>
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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</a>
|
<a class="nav-link" href="{% url 'wishlist' %}">WishList <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>
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
{% extends "auctions/layout.html" %}
|
{% extends "auctions/layout.html" %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h2>Listing:{{ Listing.title}}</h2>
|
<h2>Listing : {{ Listing.title}}</h2>
|
||||||
|
|
||||||
<img src = "{{Listing.picture}}"></img>
|
|
||||||
|
|
||||||
|
<img src = "{{Listing.picture}}" width = "100%" height= "100%"></img>
|
||||||
|
<hr>
|
||||||
|
|
||||||
<p>{{Listing.desc}}</p>
|
<p>{{Listing.desc}}</p>
|
||||||
|
|
||||||
|
|
||||||
<h3>${{Listing.price}}</h3>
|
<h3>${{Listing.price}}</h3>
|
||||||
bids so far
|
bids so far
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -30,11 +32,17 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<h5>add comment..</h5>
|
<h5>add comment..</h5>
|
||||||
|
<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!">
|
||||||
<input class="btn btn-primary" type="submit" value="Submit">
|
<input class="btn btn-primary" type="submit" value="Submit">
|
||||||
</form>
|
</form>
|
||||||
|
</p>
|
||||||
|
{% else %}
|
||||||
|
<br/>
|
||||||
|
<hr>
|
||||||
|
Log In to comment on this listing
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -0,0 +1,46 @@
|
||||||
|
{% extends "auctions/layout.html" %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h2>WatchList </h2>
|
||||||
|
<div class="row">
|
||||||
|
{% for listing in Watchlistings %}
|
||||||
|
<div class="col-sm-3">
|
||||||
|
<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">
|
||||||
|
<img class="card-img-top" src="{{ listing.picture }}" alt="Preview not found">
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
<div class="card-body">
|
||||||
|
<h4>{{ listing.title }}</h4><br>
|
||||||
|
|
||||||
|
|
||||||
|
<p class="card-text" style="font-size: large;">
|
||||||
|
<b>bid price</b> : ${{listing.price}}<br>
|
||||||
|
<b>created by</b>: {{listing.user}}<br>
|
||||||
|
|
||||||
|
<small><i> created at {{listing.date_added}}</i> </small>
|
||||||
|
</p>
|
||||||
|
<div class = "text-right">
|
||||||
|
<form action = "{% url 'watchlist' 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 %}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
|
@ -7,10 +7,11 @@ 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("wishlist", views.register, name="wishlist"),
|
path("watchlist", views.watchlist, name="wishlist"),
|
||||||
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("watch/<str:user>",views.watch,name="watchlist")
|
path("category/listing/<str:title>",views.listing,name="listing"),
|
||||||
|
path("watch/<str:title>",views.watch,name="watchlist"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django import forms
|
||||||
from .models import User,AuctionListing,Comment
|
from .models import User,AuctionListing,Comment
|
||||||
|
|
||||||
|
|
||||||
categories = ['Fashion','Electronics','Home','Sports','Toys','Automobile','Books','Video Games', 'Other']
|
categories = ['Fashion','Electronics','Home','Sports','Toys','Automobile','Books','Videogames', 'Other']
|
||||||
class Bid_Form(forms.Form):
|
class Bid_Form(forms.Form):
|
||||||
bid = 0.0
|
bid = 0.0
|
||||||
def __init__(self,bid_value):
|
def __init__(self,bid_value):
|
||||||
|
@ -15,11 +15,24 @@ class Bid_Form(forms.Form):
|
||||||
|
|
||||||
bid_value = forms.DecimalField(decimal_places=2,min_value= bid + 1)
|
bid_value = forms.DecimalField(decimal_places=2,min_value= bid + 1)
|
||||||
|
|
||||||
|
def watch(request,title):
|
||||||
|
if request.method =="POST":
|
||||||
|
listing = AuctionListing.objects.get(title=title)
|
||||||
|
if request.user in listing.watchlists.all():
|
||||||
|
request.user.watchlist.remove(listing)
|
||||||
|
else:
|
||||||
|
request.user.watchlist.add(listing)
|
||||||
|
return HttpResponseRedirect(reverse("index"))
|
||||||
|
def watchlist(request):
|
||||||
|
listings = request.user.watchlist.all()
|
||||||
|
|
||||||
|
return render(request,"auctions/watchlist.html",{
|
||||||
|
"Watchlistings": listings
|
||||||
|
})
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
listings = AuctionListing.objects.all()
|
listings = AuctionListing.objects.all()
|
||||||
if request.method == "POST":
|
|
||||||
|
|
||||||
return render(request, "auctions/index.html",{
|
return render(request, "auctions/index.html",{
|
||||||
"Listings":listings,
|
"Listings":listings,
|
||||||
|
|
||||||
|
@ -119,10 +132,14 @@ 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:
|
||||||
|
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)
|
obj = AuctionListing(title = title, desc = desc, user = request.user,price = starting_bid, picture = photo_url,category=category)
|
||||||
obj.save()
|
obj.save()
|
||||||
return render(request,"auctions/index.html")
|
return render(request,"auctions/index.html",{
|
||||||
|
"Listings" : AuctionListing.objects.all()
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
return render(request,"auctions/create_listing.html",{
|
return render(request,"auctions/create_listing.html",{
|
||||||
"categories":categories
|
"categories":categories
|
||||||
|
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Loading…
Reference in New Issue