Attempted to put 2 forms in 1 page.

Gave an error because the two forms are somehow clashing.
Co-authored-by: 's avatarpinkboheme <pinkboheme@users.noreply.github.com>
Co-authored-by: 's avatarChristine <cdeeerrr@users.noreply.github.com>
parent d4698798
...@@ -67,39 +67,13 @@ ...@@ -67,39 +67,13 @@
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#placeBidModal" <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#placeBidModal"
data-whatever="@mdo">Place Bid</button> data-whatever="@mdo">Place Bid</button>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addToFavoritesModal"
data-whatever="@mdo">Add to favorites</button>
<!-- MODAL FOR ADD TO FAVORITES--> <!-- MODAL FOR ADD TO FAVORITES-->
<div class="modal fade" id="addToFavoritesModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" <form action="" method="POST">
aria-hidden="true"> {% csrf_token %}
<div class="modal-dialog" role="document"> {{ addtofavs_form }}
<div class="modal-content"> <input type="submit" value="Add to favorites" name="Submit__favorite">
<div class="modal-header"> </form>
<h5 class="modal-title" id="exampleModalLabel">Confirm Add to Favorites</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form action="" method="POST">
<div class="form-group">
{% csrf_token %}
{{ addtofavs_form }}
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-secondary" name="Submit"> Submit </button>
</div>
</form>
</div>
</div>
</div>
<!-- MODAL FOR BIDDING --> <!-- MODAL FOR BIDDING -->
<div class="modal fade" id="placeBidModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" <div class="modal fade" id="placeBidModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true"> aria-hidden="true">
...@@ -123,7 +97,7 @@ ...@@ -123,7 +97,7 @@
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-secondary" name="Submit"> Submit </button> <button type="submit" class="btn btn-secondary" name="Submit__Bid"> Submit </button>
</div> </div>
</form> </form>
......
...@@ -18,7 +18,6 @@ class PlaceBidForm(forms.ModelForm): ...@@ -18,7 +18,6 @@ class PlaceBidForm(forms.ModelForm):
auction = self.cleaned_data.get('auctionid') auction = self.cleaned_data.get('auctionid')
auction_item = Item.objects.get(auction=auction) auction_item = Item.objects.get(auction=auction)
auction_bids = AuctionBid.objects.filter(auctionid=auction) auction_bids = AuctionBid.objects.filter(auctionid=auction)
if not auction_bids: if not auction_bids:
...@@ -46,4 +45,7 @@ class AddToFavoritesForm(forms.ModelForm): ...@@ -46,4 +45,7 @@ class AddToFavoritesForm(forms.ModelForm):
class Meta: class Meta:
model = UserFavorites model = UserFavorites
fields = ['userid','auctionid'] fields = ['userid','auctionid']
widgets = {'auctionid': forms.HiddenInput()} widgets = {
\ No newline at end of file 'auctionid': forms.HiddenInput(),
'userid': forms.HiddenInput()
}
\ No newline at end of file
...@@ -21,6 +21,7 @@ class Auction(models.Model): ...@@ -21,6 +21,7 @@ class Auction(models.Model):
db_table = 'auction' db_table = 'auction'
class AuctionBid(models.Model): class AuctionBid(models.Model):
bidno = models.AutoField(primary_key=True) bidno = models.AutoField(primary_key=True)
amount = models.DecimalField(max_digits=15, decimal_places=4) amount = models.DecimalField(max_digits=15, decimal_places=4)
...@@ -107,6 +108,7 @@ class BoodleUser(models.Model): ...@@ -107,6 +108,7 @@ class BoodleUser(models.Model):
class Meta: class Meta:
managed = False managed = False
db_table = 'boodleuser' db_table = 'boodleuser'
class DjangoAdminLog(models.Model): class DjangoAdminLog(models.Model):
...@@ -164,6 +166,8 @@ class Item(models.Model): ...@@ -164,6 +166,8 @@ class Item(models.Model):
class Meta: class Meta:
managed = False managed = False
db_table = 'item' db_table = 'item'
def __str__(self):
return self.itemname
class Store(models.Model): class Store(models.Model):
......
...@@ -21,7 +21,7 @@ def homepage(request): ...@@ -21,7 +21,7 @@ def homepage(request):
# Filter by auctions scheduled at most a week from now # Filter by auctions scheduled at most a week from now
week_range = datetime.now() + timedelta(days=7) week_range = datetime.now() + timedelta(days=7)
auctions_soon = Auction.objects.filter(auctionstart__lt=week_range).exclude(auctionstart__lte=datetime.now()) auctions_soon = Auction.objects.filter(auctionstart__lt=week_range).exclude(auctionstart__lte=datetime.now())
for auction in auctions_soon: # for auction in auctions_soon:
print(auction) print(auction)
context = { context = {
...@@ -31,7 +31,7 @@ def homepage(request): ...@@ -31,7 +31,7 @@ def homepage(request):
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)
...@@ -39,13 +39,12 @@ def auction(request, pk): ...@@ -39,13 +39,12 @@ def auction(request, pk):
auction_item = auction.itemid auction_item = auction.itemid
# Auction bids # Auction bids
auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime') auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime')
highest_bid = auction_item.floorprice highest_bid = auction_item.floorprice
if auction_bids: if auction_bids:
highest_bid = auction_bids[0].amount highest_bid = auction_bids[0].amount
# PLACE BID FORM # PLACE BID FORM AND ADD TO FAVES FORM
form = PlaceBidForm(initial={'auctionid':auction}) form = PlaceBidForm(initial={'auctionid':auction})
if request.method == 'POST': if request.method == 'POST':
form = PlaceBidForm(request.POST,initial={'auctionid':auction}) form = PlaceBidForm(request.POST,initial={'auctionid':auction})
...@@ -57,20 +56,30 @@ def auction(request, pk): ...@@ -57,20 +56,30 @@ def auction(request, pk):
return redirect(f"/auction/{pk}") return redirect(f"/auction/{pk}")
except: except:
pass pass
# ADD TO FAVORITES FORM
addtofavs_form = AddToFavoritesForm()
if request.method == 'POST':
addtofavs_form = AddToFavoritesForm(request.POST)
# if addtofavs_form.is_valid():
# try:
# amount = addtofavs_form.cleaned_data['amount']
# new_bid = AuctionBid(amount=amount,bidtime=datetime.now(),auctionid=auction)
# new_bid.save()
# return redirect(f"/auction/{pk}")
# except:
# pass
# ADD TO FAVORITES FORM REQUEST POST
user = BoodleUser.objects.get(userid=1) # Current auction ID
user_profile = user.userid # specific id
auction_profile = auction.auctionid
addtofavs_form = AddToFavoritesForm(
initial={ 'auctionid':auction_profile, 'userid':user_profile
})
if request.method == 'POST' and not form.is_valid():
addtofavs_form = AddToFavoritesForm(
request.POST,
initial= {
'auctionid':auction_profile,
'userid':user_profile
})
print(request.POST)
if addtofavs_form.is_valid():
new_favorite = UserFavorites(auctionid=auction, user_profile=user)
new_favorite.save()
print(request.POST)
return redirect(f"/auction/{pk}")
print("This is: ", UserFavorites.objects.all())
context = { context = {
'item_name':auction_item.itemname, 'item_name':auction_item.itemname,
......
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