add category
This commit is contained in:
parent
bd89ca0eed
commit
192defed3b
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"python.pythonPath": "C:\\Users\\bncha\\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe",
|
||||
"python.pythonPath": "C:\\ProgramData\\Anaconda3\\python.exe",
|
||||
"python.dataScience.jupyterServerURI": "local"
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,9 +1,8 @@
|
|||
from django.contrib import admin
|
||||
from .models import User
|
||||
from .models import AuctionListing
|
||||
from .models import Comments
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(User)
|
||||
admin.site.register(AuctionListing)
|
||||
admin.site.register(Comments)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.0.8 on 2020-10-11 16:42
|
||||
# Generated by Django 3.0.8 on 2020-10-18 16:09
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.auth.models
|
||||
|
@ -50,15 +50,14 @@ class Migration(migrations.Migration):
|
|||
('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)),
|
||||
('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='Comments',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('comment', models.CharField(max_length=1000)),
|
||||
('title', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='auction_title', to='auctions.AuctionListing')),
|
||||
],
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='watchlist',
|
||||
field=models.ManyToManyField(blank=True, related_name='watchlist', to='auctions.AuctionListing'),
|
||||
),
|
||||
]
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
# Generated by Django 3.0.8 on 2020-10-11 17:53
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auctions', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='auctionlisting',
|
||||
name='user',
|
||||
field=models.ForeignKey(default=' ', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
# 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',
|
||||
),
|
||||
]
|
|
@ -0,0 +1,20 @@
|
|||
# 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,18 +0,0 @@
|
|||
# Generated by Django 3.0.8 on 2020-10-11 18:37
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auctions', '0002_auto_20201011_2323'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='auctionlisting',
|
||||
name='picture',
|
||||
field=models.ImageField(null=True, upload_to=''),
|
||||
),
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 3.0.8 on 2020-10-13 03:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auctions', '0003_auto_20201012_0007'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='auctionlisting',
|
||||
name='picture',
|
||||
field=models.URLField(null=True),
|
||||
),
|
||||
]
|
|
@ -1,28 +0,0 @@
|
|||
# Generated by Django 3.0.8 on 2020-10-16 11:00
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auctions', '0004_auto_20201013_0925'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='user',
|
||||
name='watchlist',
|
||||
field=models.ManyToManyField(blank=True, related_name='watchlist', to='auctions.AuctionListing'),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='bidding',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('bid', models.DecimalField(decimal_places=2, max_digits=10)),
|
||||
('bidder', models.ForeignKey(default=' ', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 3.0.8 on 2020-10-16 16:29
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auctions', '0005_auto_20201016_1630'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='auctionlisting',
|
||||
name='category',
|
||||
field=models.CharField(default=' ', max_length=64),
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -2,24 +2,20 @@ from django.contrib.auth.models import AbstractUser
|
|||
from django.db import models
|
||||
|
||||
class User(AbstractUser):
|
||||
watchlist = models.ManyToManyField('AuctionListing',blank = True,related_name="watchlist")
|
||||
watchlist = models.ManyToManyField('AuctionListing',blank = True,related_name="watchlist")
|
||||
|
||||
class AuctionListing(models.Model):
|
||||
title = models.CharField(max_length = 64,primary_key = True)
|
||||
user = models.ForeignKey(User,on_delete = models.CASCADE,default = " ")
|
||||
user = models.ForeignKey(User,on_delete = models.CASCADE)
|
||||
price = models.DecimalField(max_digits = 10,decimal_places = 2)
|
||||
desc = models.CharField(max_length = 1000)
|
||||
picture = models.URLField(null=True)
|
||||
category = models.CharField(max_length = 64,default = " ")
|
||||
category = models.CharField(max_length = 64)
|
||||
date_added = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title}: {self.price},{self.desc},{self.picture}"
|
||||
class Comments(models.Model):
|
||||
title = models.ForeignKey(AuctionListing,on_delete = models.CASCADE,related_name="auction_title")
|
||||
comment = models.CharField(max_length = 1000)
|
||||
return f"{self.title}: {self.price},{self.desc},{self.picture},{self.category},{self.date_added}"
|
||||
|
||||
|
||||
|
||||
|
||||
class bidding(models.Model):
|
||||
bidder = models.ForeignKey(User,on_delete = models.CASCADE,default = " ")
|
||||
bid = models.DecimalField(max_digits = 10,decimal_places = 2)
|
|
@ -12,12 +12,12 @@
|
|||
|
||||
<hr>
|
||||
<div class="card-body">
|
||||
<h4>{{ listing.title }}</h4><br>
|
||||
<h4>{{ list.title }}</h4><br>
|
||||
|
||||
|
||||
<p class="card-text" style="font-size: large;">
|
||||
<b>bid price</b> : ${{listing.price}}<br>
|
||||
<b>created by</b>: {{listing.user}}
|
||||
<b>bid price</b> : ${{list.price}}<br>
|
||||
<b>created by</b>: {{list.user}}
|
||||
</p>
|
||||
<div class = "text-right">
|
||||
<input class="form-check-input" type="checkbox" value="" id="watch">
|
||||
|
|
|
@ -20,8 +20,12 @@
|
|||
<b>created by</b>: {{listing.user}}
|
||||
</p>
|
||||
<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>
|
||||
<form action = "{% url 'index' %}" method="POST">
|
||||
{% csrf_token %}
|
||||
{{ watch_form }}
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
</li>
|
||||
{% if user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'wishlist' %}">WishList{% block watch %}def{% endblock %}</a>
|
||||
<a class="nav-link" href="{% url 'wishlist' %}">WishList</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'create' %}">Create Listing</a>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
{% extends "auctions/layout.html" %}
|
||||
|
||||
{% block body %}
|
||||
|
|
|
@ -11,5 +11,5 @@ urlpatterns = [
|
|||
path("create", views.create, name="create"),
|
||||
path("categories", views.category, name="categories"),
|
||||
path("category/<str:cat_name>",views.category,name="indiv_categories"),
|
||||
path("listing/<str:title>",views.listing,name="listing")
|
||||
path("listing/<str:title>",views.listing,name="listing")
|
||||
]
|
||||
|
|
|
@ -3,28 +3,43 @@ from django.db import IntegrityError
|
|||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse
|
||||
from django.core.files import File
|
||||
from django.core.files.temp import NamedTemporaryFile
|
||||
from django.core.files.base import ContentFile
|
||||
import requests
|
||||
from .models import User,AuctionListing,Comments
|
||||
from django import forms
|
||||
from .models import User,AuctionListing
|
||||
|
||||
|
||||
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):
|
||||
self.bid = bid_value
|
||||
|
||||
bid_value = forms.DecimalField(decimal_places=2,min_value= bid + 1)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
return render(request, "auctions/index.html",{
|
||||
"Listings":listings
|
||||
"Listings":listings,
|
||||
"watch_form": Watch_Form()
|
||||
})
|
||||
|
||||
def listing(request,title):
|
||||
"""
|
||||
docstring
|
||||
"""
|
||||
listing = AuctionListing.objects.get(pk = title)
|
||||
listings = AuctionListing.objects.get(pk = title)
|
||||
return render(request,"auctions/listing.html",{
|
||||
"Listing": listing
|
||||
"Listing": listings
|
||||
})
|
||||
def category(request,cat_name = None):
|
||||
"""
|
||||
|
@ -33,11 +48,12 @@ def category(request,cat_name = None):
|
|||
if( cat_name != None):
|
||||
if cat_name.capitalize() in categories:
|
||||
|
||||
listings = AuctionListing.objects.get(category=cat_name.capitalize())
|
||||
listings = AuctionListing.objects.filter(category=cat_name.capitalize())
|
||||
print(listings)
|
||||
|
||||
return render(request, "auctions/category.html",{
|
||||
"listings":listings
|
||||
"listings":listings,
|
||||
"cat_name": cat_name
|
||||
|
||||
})
|
||||
|
||||
|
@ -109,7 +125,6 @@ def create(request):
|
|||
obj.save()
|
||||
return render(request,"auctions/index.html")
|
||||
else:
|
||||
categories = ['Fashion','Electronics','Home','Sports','Toys','Automobile','Books','Video Games', 'Other']
|
||||
return render(request,"auctions/create_listing.html",{
|
||||
"categories":categories
|
||||
})
|
||||
|
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Loading…
Reference in New Issue