Commit 35191150 authored by Christine Dela Rosa's avatar Christine Dela Rosa

Create addItemForm, Display items on store

Create temporary html to access specific storeid as well, delete once url handling is fixed
parent 19433c19
...@@ -16,10 +16,14 @@ ...@@ -16,10 +16,14 @@
<div class="item-image-container"></div> <div class="item-image-container"></div>
</div> </div>
<div class=" col-lg-5 col-md-6">ITEM FORM CONTAINER <div class=" col-lg-5 col-md-6">ITEM FORM CONTAINER
<div class="item-form-container"></div> <div class="item-form-container">
<form action="" method="POST">
<button type="button">Add Item</button> {% csrf_token %}
{{ form.as_p }}
</div>
<button type="submit" name="Add Item"> Add Item </button>
</form>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<div class="store-banner"><img src="https://www.w3schools.com/howto/img_snow_wide.jpg"> <div class="store-banner"><img src="https://www.w3schools.com/howto/img_snow_wide.jpg">
<div class="store-info"> <div class="store-info">
<img src="https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png"> <img src="https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png">
<h1>STORE NAME HERE</h1> <h1>{{ current_store.storename }}</h1>
<p>@username</p> <p>@username</p>
<button class="edit-shop-btn" type="button">Edit Shop Info</button> <button class="edit-shop-btn" type="button">Edit Shop Info</button>
</div> </div>
...@@ -34,16 +34,22 @@ ...@@ -34,16 +34,22 @@
<div class="store-item-container"> <div class="store-item-container">
{% if store_items %}
{% for item in store_items %}
<div class="store-item"> <div class="store-item">
<img src="https://www.kurin.com/wp-content/uploads/placeholder-square.jpg"> <img src="https://www.kurin.com/wp-content/uploads/placeholder-square.jpg">
<div class="item-info"> <div class="item-info">
<h4>Itemname</h4> <h4>{{ item.itemname }}</h4>
<p>Itemdescription <span class="item-price">PHP 500</span></p> <p>{{item.itemspecs}} <span class="item-price">PHP {{item.floorprice}}</span></p>
</div> </div>
<div class="item-btns"> <button>Auction</button> <button>Edit</button> <button>Delete</button> <div class="item-btns"> <button>Auction</button> <button>Edit</button> <button>Delete</button>
</div> </div>
</div> </div>
<div class="store-item"> {% endfor %}
{% else %}
<h4 text-align="center"> Your Inventory is empty. </h4>
{% endif %}
<!-- <div class="store-item">
<img src="https://www.kurin.com/wp-content/uploads/placeholder-square.jpg"> <img src="https://www.kurin.com/wp-content/uploads/placeholder-square.jpg">
<div class="item-info"> <div class="item-info">
<h4>Itemname</h4> <h4>Itemname</h4>
...@@ -51,52 +57,7 @@ ...@@ -51,52 +57,7 @@
</div> </div>
<div class="item-btns"> <button>Auction</button> <button>Edit</button> <button>Delete</button> <div class="item-btns"> <button>Auction</button> <button>Edit</button> <button>Delete</button>
</div> </div>
</div> </div> -->
<div class="store-item">
<img src="https://www.kurin.com/wp-content/uploads/placeholder-square.jpg">
<div class="item-info">
<h4>Itemname</h4>
<p>Itemdescription <span class="item-price">PHP 500</span></p>
</div>
<div class="item-btns"> <button>Auction</button> <button>Edit</button> <button>Delete</button>
</div>
</div>
<div class="store-item">
<img src="https://www.kurin.com/wp-content/uploads/placeholder-square.jpg">
<div class="item-info">
<h4>Itemname</h4>
<p>Itemdescription <span class="item-price">PHP 500</span></p>
</div>
<div class="item-btns"> <button>Auction</button> <button>Edit</button> <button>Delete</button>
</div>
</div>
<div class="store-item">
<img src="https://www.kurin.com/wp-content/uploads/placeholder-square.jpg">
<div class="item-info">
<h4>Itemname</h4>
<p>Itemdescription <span class="item-price">PHP 500</span></p>
</div>
<div class="item-btns"> <button>Auction</button> <button>Edit</button> <button>Delete</button>
</div>
</div>
<div class="store-item">
<img src="https://www.kurin.com/wp-content/uploads/placeholder-square.jpg">
<div class="item-info">
<h4>Itemname</h4>
<p>Itemdescription <span class="item-price">PHP 500</span></p>
</div>
<div class="item-btns"> <button>Auction</button> <button>Edit</button> <button>Delete</button>
</div>
</div>
<div class="store-item">
<img src="https://www.kurin.com/wp-content/uploads/placeholder-square.jpg">
<div class="item-info">
<h4>Itemname</h4>
<p>Itemdescription <span class="item-price">PHP 500</span></p>
</div>
<div class="item-btns"> <button>Auction</button> <button>Edit</button> <button>Delete</button>
</div>
</div>
...@@ -107,9 +68,9 @@ ...@@ -107,9 +68,9 @@
<div class="store-btns-container"> <div class="store-btns-container">
<button type="button"><a href="startauction">Start Auction</a></button> <button type="button"><a href="/startauction">Start Auction</a></button>
<button type="button"><a href="additem">Add Item</a></button> <button type="button"><a href="{% url 'additemid' current_store.storeid %}">Add Item</a></button>
</div> </div>
] ]
</div> </div>
......
{% extends 'boodlesite\templates\base.html' %}
{% load static %}
{% block title %}My Store{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<h2>This is a temp page to access storeid 1 (and not thru the navbar)</h2>
<p>Remove this page once nav bar is personalized that it accesses the logged in user's store</p>
<h1 text-align="center">Link to My Store: <a href="{% url 'storeid' current_store.storeid %}">{{ current_store.storename }}</a></h1>
{% endblock %}
\ No newline at end of file
from django import forms from django import forms
from django.forms import (ModelForm, from django.forms import (ModelForm,
TextInput, Textarea, widgets) TextInput, Textarea, widgets)
from django.utils.translation import gettext_lazy as _
from .models import * from .models import *
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
...@@ -28,3 +29,15 @@ class PlaceBidForm(forms.ModelForm): ...@@ -28,3 +29,15 @@ class PlaceBidForm(forms.ModelForm):
highest_bid = auction_bids.latest('bidtime').amount highest_bid = auction_bids.latest('bidtime').amount
if form_amount <= highest_bid: if form_amount <= highest_bid:
raise ValidationError('Please enter an amount higher than the current highest bid.') raise ValidationError('Please enter an amount higher than the current highest bid.')
class AddItemForm(forms.ModelForm):
class Meta:
model = Item
fields = ['itemname','itemspecs','floorprice','storeid']
widgets = {'storeid': forms.HiddenInput()}
labels = {
'itemname': _('Item Name'),
'itemspecs': _('Item Description'),
'floorprice': _('Floor Price')
}
\ No newline at end of file
...@@ -151,7 +151,18 @@ class Item(models.Model): ...@@ -151,7 +151,18 @@ class Item(models.Model):
itemspecs = models.CharField(max_length=700) itemspecs = models.CharField(max_length=700)
floorprice = models.DecimalField(max_digits=15, decimal_places=4) floorprice = models.DecimalField(max_digits=15, decimal_places=4)
sellprice = models.DecimalField(max_digits=15, decimal_places=4, blank=True, null=True) sellprice = models.DecimalField(max_digits=15, decimal_places=4, blank=True, null=True)
storeid = models.ForeignKey('Store', models.DO_NOTHING, db_column='storeid')
class Meta: class Meta:
managed = False managed = False
db_table = 'item' db_table = 'item'
class Store(models.Model):
storeid = models.AutoField(primary_key=True)
storename = models.CharField(max_length=255)
storedesc = models.CharField(max_length=700)
class Meta:
managed = False
db_table = 'store'
...@@ -5,10 +5,12 @@ from .views import * ...@@ -5,10 +5,12 @@ from .views import *
urlpatterns = [ urlpatterns = [
path('', homepage, name='index'), path('', homepage, name='index'),
path('auction', auction, name='auction'), path('auction', auction, name='auction'),
path('auction/<int:pk>/',auction,name='auctionid'), path('auction/<int:pk>/',auction, name='auctionid'),
path('error404', error404, name='error404'), path('error404', error404, name='error404'),
path('store',mystore,name='store'), path('store', tempstore, name='store'),
path('additem',addItem,name='additem'), path('store/<int:pk>', mystore, name='storeid'),
path('startauction',startAuction,name='startauction'), path('additem', addItem, name='additem'),
path('additem/<int:pk>', addItem, name='additemid'),
path('startauction', startAuction, name='startauction'),
] ]
\ No newline at end of file
...@@ -4,7 +4,6 @@ from django.http import HttpResponse ...@@ -4,7 +4,6 @@ from django.http import HttpResponse
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from .models import * from .models import *
from .forms import * from .forms import *
...@@ -16,7 +15,7 @@ def homepage(request): ...@@ -16,7 +15,7 @@ def homepage(request):
# Filter by auctions happening right now # Filter by auctions happening right now
auctions_now = Auction.objects.filter(auctionstart__lt=datetime.now(),auctionend__gt=datetime.now()) auctions_now = Auction.objects.filter(auctionstart__lt=datetime.now(),auctionend__gt=datetime.now())
for auction in auctions_now: # for auction in auctions_now:
print(auction) print(auction)
# Filter by auctions scheduled at most a week from now # Filter by auctions scheduled at most a week from now
...@@ -27,12 +26,13 @@ def homepage(request): ...@@ -27,12 +26,13 @@ def homepage(request):
context = { context = {
'auctions_now': auctions_now, 'auctions_now': auctions_now,
'auctions_soon': auctions_soon 'auctions_soon': auctions_soon,
} }
return render(request, "boodlesite/templates/index.html",context) return render(request, "boodlesite/templates/index.html",context)
def auction(request, pk): def auction(request, pk):
# Current auction ID # Current auction ID
auction = Auction.objects.get(pk=pk) auction = Auction.objects.get(pk=pk)
# Item for auction # Item for auction
...@@ -65,7 +65,7 @@ def auction(request, pk): ...@@ -65,7 +65,7 @@ def auction(request, pk):
'item_floor_price': auction_item.floorprice, 'item_floor_price': auction_item.floorprice,
'highest_bid': highest_bid, 'highest_bid': highest_bid,
'auction_end': auction.auctionend, 'auction_end': auction.auctionend,
'form' : form 'form' : form,
} }
if auction.auctionend < datetime.now(): if auction.auctionend < datetime.now():
...@@ -79,11 +79,60 @@ def auction(request, pk): ...@@ -79,11 +79,60 @@ def auction(request, pk):
def error404(request): def error404(request):
return render(request, "boodlesite/templates/error404.html") return render(request, "boodlesite/templates/error404.html")
def mystore(request): def tempstore(request): # temp view
return render(request, "boodlesite/templates/store.html")
#### Access to store 1 [ edit accordingly when it becomes accessible thru a user ] ####
current_store = Store.objects.get(storeid=1)
context = {
'current_store':current_store #### used for navbar, access to store 1
}
return render(request, "boodlesite/templates/tempstore.html", context)
def mystore(request, pk):
#### Access to store 1 [ edit accordingly when it becomes accessible thru a user ] ####
current_store = Store.objects.get(pk=pk)
store_items = Item.objects.filter(storeid=pk)
context = {
'current_store':current_store,
'store_items':store_items
}
return render(request, "boodlesite/templates/store.html", context)
def addItem(request): def addItem(request, pk):
return render(request, "boodlesite/templates/additem.html")
# Current Store, pk here is the storeid
current_store = Store.objects.get(pk=pk)
form = AddItemForm(initial={'storeid':current_store})
if request.method == 'POST':
form = AddItemForm(request.POST,initial={'storeid':current_store})
if form.is_valid():
form.save()
return redirect('storeid', pk=pk)
context = {
'form':form,
'current_store': current_store # access to store 1
}
return render(request, "boodlesite/templates/additem.html", context)
def startAuction(request): def startAuction(request):
return render(request, "boodlesite/templates/startauction.html")
#### Access to store 1 [ edit accordingly when it becomes accessible thru a user ] ####
current_store = Store.objects.get(storeid=1)
context = {
'current_store':current_store
}
return render(request, "boodlesite/templates/startauction.html", context)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment