diff --git a/auctions/__pycache__/admin.cpython-37.pyc b/auctions/__pycache__/admin.cpython-37.pyc index 84f54ed..dfd5cc2 100644 Binary files a/auctions/__pycache__/admin.cpython-37.pyc and b/auctions/__pycache__/admin.cpython-37.pyc differ diff --git a/auctions/__pycache__/models.cpython-37.pyc b/auctions/__pycache__/models.cpython-37.pyc index 3a29ecc..6d09c6e 100644 Binary files a/auctions/__pycache__/models.cpython-37.pyc and b/auctions/__pycache__/models.cpython-37.pyc differ diff --git a/auctions/__pycache__/urls.cpython-37.pyc b/auctions/__pycache__/urls.cpython-37.pyc index 8f0d091..d413074 100644 Binary files a/auctions/__pycache__/urls.cpython-37.pyc and b/auctions/__pycache__/urls.cpython-37.pyc differ diff --git a/auctions/__pycache__/views.cpython-37.pyc b/auctions/__pycache__/views.cpython-37.pyc index 57c37f1..6b111cb 100644 Binary files a/auctions/__pycache__/views.cpython-37.pyc and b/auctions/__pycache__/views.cpython-37.pyc differ diff --git a/auctions/admin.py b/auctions/admin.py index 466ccb9..3fac663 100644 --- a/auctions/admin.py +++ b/auctions/admin.py @@ -1,8 +1,8 @@ from django.contrib import admin from .models import User -from .models import AuctionListing +from .models import AuctionListing,Comment # Register your models here. admin.site.register(User) admin.site.register(AuctionListing) - +admin.site.register(Comment) diff --git a/auctions/migrations/0004_comment.py b/auctions/migrations/0004_comment.py new file mode 100644 index 0000000..87da767 --- /dev/null +++ b/auctions/migrations/0004_comment.py @@ -0,0 +1,25 @@ +# 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)), + ], + ), + ] diff --git a/auctions/migrations/0005_auto_20201018_2304.py b/auctions/migrations/0005_auto_20201018_2304.py new file mode 100644 index 0000000..de1ed5d --- /dev/null +++ b/auctions/migrations/0005_auto_20201018_2304.py @@ -0,0 +1,23 @@ +# 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), + ), + ] diff --git a/auctions/migrations/__pycache__/0004_comment.cpython-37.pyc b/auctions/migrations/__pycache__/0004_comment.cpython-37.pyc new file mode 100644 index 0000000..1e76d7f Binary files /dev/null and b/auctions/migrations/__pycache__/0004_comment.cpython-37.pyc differ diff --git a/auctions/migrations/__pycache__/0005_auto_20201018_2304.cpython-37.pyc b/auctions/migrations/__pycache__/0005_auto_20201018_2304.cpython-37.pyc new file mode 100644 index 0000000..3d2de5c Binary files /dev/null and b/auctions/migrations/__pycache__/0005_auto_20201018_2304.cpython-37.pyc differ diff --git a/auctions/models.py b/auctions/models.py index 655ce55..414cd00 100644 --- a/auctions/models.py +++ b/auctions/models.py @@ -2,7 +2,7 @@ from django.contrib.auth.models import AbstractUser from django.db import models class User(AbstractUser): - watchlist = models.ManyToManyField('AuctionListing',blank = True,related_name="watchlist") + pass class AuctionListing(models.Model): title = models.CharField(max_length = 64,primary_key = True) @@ -12,10 +12,17 @@ class AuctionListing(models.Model): picture = models.URLField(null=True) category = models.CharField(max_length = 64) date_added = models.DateTimeField(auto_now_add=True) + watchlist = models.ManyToManyField(User,blank = True,related_name="watchlist") def __str__(self): return f"{self.title}: {self.price},{self.desc},{self.picture},{self.category},{self.date_added}" +class Comment(models.Model): + listing = models.ForeignKey(AuctionListing,on_delete = models.CASCADE,related_name="comments") + user = models.ForeignKey(User,related_name="commited_user",on_delete=models.CASCADE) + body = models.TextField() + date_added = models.DateTimeField(auto_now_add=True) - + def __str__(self): + return '%s - %s' % (self.listing.title, self.user) diff --git a/auctions/templates/auctions/index.html b/auctions/templates/auctions/index.html index 3ab8196..e46d39d 100644 --- a/auctions/templates/auctions/index.html +++ b/auctions/templates/auctions/index.html @@ -17,12 +17,14 @@

bid price : ${{listing.price}}
- created by: {{listing.user}} -

+ created by: {{listing.user}}
+ + created at {{listing.date_added}} +

-
+ {% csrf_token %} - {{ watch_form }} +
diff --git a/auctions/templates/auctions/listing.html b/auctions/templates/auctions/listing.html index 5fee189..1bdcb7d 100644 --- a/auctions/templates/auctions/listing.html +++ b/auctions/templates/auctions/listing.html @@ -14,5 +14,27 @@
+

Comments ...

+ + {% if not Listing.comments.all %} + No comments Yet.... + {% else %} + {% for comment in Listing.comments.all %} + {{comment.user}} - {{comment.date_added}} +
+ {{ comment.body }} +
+ {% endfor %} + + + {% endif %} + {% if user.is_authenticated %} +
add comment..
+
+ {% csrf_token %} + + +
+ {% endif %} {% endblock %} \ No newline at end of file diff --git a/auctions/urls.py b/auctions/urls.py index 2a59bbc..71953be 100644 --- a/auctions/urls.py +++ b/auctions/urls.py @@ -10,6 +10,7 @@ urlpatterns = [ path("wishlist", views.register, name="wishlist"), path("create", views.create, name="create"), path("categories", views.category, name="categories"), - path("category/",views.category,name="indiv_categories"), - path("listing/",views.listing,name="listing") + path("category/",views.category,name="individual_categories"), + path("listing/",views.listing,name="listing"), + path("watch/",views.watch,name="watchlist") ] diff --git a/auctions/views.py b/auctions/views.py index 27d0486..8fa8bca 100644 --- a/auctions/views.py +++ b/auctions/views.py @@ -4,12 +4,10 @@ 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 +from .models import User,AuctionListing,Comment categories = ['Fashion','Electronics','Home','Sports','Toys','Automobile','Books','Video Games', 'Other'] -class Watch_Form(forms.Form): - watch_this = forms.BooleanField(required=False) class Bid_Form(forms.Form): bid = 0.0 def __init__(self,bid_value): @@ -20,17 +18,11 @@ class Bid_Form(forms.Form): def index(request): listings = AuctionListing.objects.all() - watch_form = Watch_Form(request.POST) - if watch_form.is_valid(): - print("asdf") - watch = watch_form.cleaned_data["watch_this"] - print(watch) - - - + if request.method == "POST": + return render(request, "auctions/index.html",{ "Listings":listings, - "watch_form": Watch_Form() + }) def listing(request,title): @@ -38,9 +30,15 @@ def listing(request,title): docstring """ listings = AuctionListing.objects.get(pk = title) + if request.method == "POST": + body = request.POST["comment_body"] + comment = Comment(user=request.user,listing=listings,body = body) + comment.save() + return render(request,"auctions/listing.html",{ "Listing": listings }) + def category(request,cat_name = None): """ docstring @@ -61,6 +59,7 @@ def category(request,cat_name = None): return render(request,"auctions/category_listing.html",{ "categories": categories }) + def login_view(request): if request.method == "POST": @@ -128,3 +127,6 @@ def create(request): return render(request,"auctions/create_listing.html",{ "categories":categories }) + + + diff --git a/commerce/__pycache__/settings.cpython-37.pyc b/commerce/__pycache__/settings.cpython-37.pyc index dcbd05c..098eb34 100644 Binary files a/commerce/__pycache__/settings.cpython-37.pyc and b/commerce/__pycache__/settings.cpython-37.pyc differ diff --git a/db.sqlite3 b/db.sqlite3 index 28f0b19..7b8a4b3 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ