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

Create StartAuctionForm, Display auctions on homepage

parent 29a17ac0
...@@ -9,11 +9,18 @@ ...@@ -9,11 +9,18 @@
{% block content %} {% block content %}
<div class="container"><button type="button">Save Auction</button> <div class="container">
<form action="" method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" name="savesauction">Save Auction</button>
</form>
</div> </div>
<!-- Form fields: <!-- Form fields:
[Auction Title] [Auction Title]
[Auction Description]
Drop down: [Select time for Auction] Drop down: [Select time for Auction]
Set Auction timer: Set Auction timer:
Start: Start:
...@@ -22,6 +29,4 @@ End: ...@@ -22,6 +29,4 @@ End:
Drop down: [Month] [Day] [Year] Time: [Hour] : [Minute] Drop down: [Month] [Day] [Year] Time: [Hour] : [Minute]
--> -->
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
<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="{% url 'startauctionid' current_store.storeid %}">Start Auction</a></button>
<button type="button"><a href="{% url 'additemid' current_store.storeid %}">Add Item</a></button> <button type="button"><a href="{% url 'additemid' current_store.storeid %}">Add Item</a></button>
</div> </div>
......
from datetime import datetime
from django import forms from django import forms
from django.forms import (ModelForm, from django.forms import (ModelForm,
TextInput, Textarea, widgets) TextInput, Textarea, widgets)
...@@ -41,3 +42,23 @@ class AddItemForm(forms.ModelForm): ...@@ -41,3 +42,23 @@ class AddItemForm(forms.ModelForm):
'itemspecs': _('Item Description'), 'itemspecs': _('Item Description'),
'floorprice': _('Floor Price') 'floorprice': _('Floor Price')
} }
class StartAuctionForm(forms.ModelForm):
class Meta:
model = Auction
fields = '__all__'
labels = {
'title': _('Auction Title'),
'info': _('Auction Description'),
'auctionstart': _('Starting time'),
'auctionend': _('Closing time'),
'itemid': _('Item up for auction')
}
# datetime_format = ['%Y-%m-%d %H:%M']
# widgets = { 'auctionstart' : forms.DateTimeInput(input_formats=['%Y-%m-%d %H:%M']), 'auctionend' : forms.DateTimeInput(input_formats=['%Y-%m-%d %H:%M'])}
# vv fix later, is missing time widget
# widgets = { 'auctionstart' : forms.SelectDateWidget, 'auctionend':forms.SelectDateWidget}
# 'itemid': forms.HiddenInput()}
\ No newline at end of file
...@@ -157,6 +157,9 @@ class Item(models.Model): ...@@ -157,6 +157,9 @@ class Item(models.Model):
managed = False managed = False
db_table = 'item' db_table = 'item'
def __str__(self):
return '%s' % (self.itemname)
class Store(models.Model): class Store(models.Model):
storeid = models.AutoField(primary_key=True) storeid = models.AutoField(primary_key=True)
......
...@@ -12,5 +12,6 @@ urlpatterns = [ ...@@ -12,5 +12,6 @@ urlpatterns = [
path('additem', addItem, name='additem'), path('additem', addItem, name='additem'),
path('additem/<int:pk>', addItem, name='additemid'), path('additem/<int:pk>', addItem, name='additemid'),
path('startauction', startAuction, name='startauction'), path('startauction', startAuction, name='startauction'),
path('startauction/<int:pk>', startAuction, name='startauctionid'),
] ]
\ No newline at end of file
...@@ -125,13 +125,26 @@ def addItem(request, pk): ...@@ -125,13 +125,26 @@ def addItem(request, pk):
return render(request, "boodlesite/templates/additem.html", context) return render(request, "boodlesite/templates/additem.html", context)
def startAuction(request): def startAuction(request, pk):
# pk is store id
current_store = Store.objects.get(pk=pk)
# get items under this store
store_items = Item.objects.filter(storeid=pk)
form = StartAuctionForm(initial={'storeid':current_store})
if request.method == 'POST':
form = StartAuctionForm(request.POST,initial={'storeid':current_store})
if form.is_valid():
form.save()
return redirect('storeid', pk=pk)
#### Access to store 1 [ edit accordingly when it becomes accessible thru a user ] ####
current_store = Store.objects.get(storeid=1)
context = { context = {
'current_store':current_store 'current_store':current_store,
'store_items': store_items,
'form':form
} }
......
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