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 @@
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#placeBidModal"
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-->
<div class="modal fade" id="addToFavoritesModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<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>
<input type="submit" value="Add to favorites" name="Submit__favorite">
</form>
</div>
</div>
</div>
<!-- MODAL FOR BIDDING -->
<div class="modal fade" id="placeBidModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
......@@ -123,7 +97,7 @@
<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>
<button type="submit" class="btn btn-secondary" name="Submit__Bid"> Submit </button>
</div>
</form>
......
......@@ -18,7 +18,6 @@ class PlaceBidForm(forms.ModelForm):
auction = self.cleaned_data.get('auctionid')
auction_item = Item.objects.get(auction=auction)
auction_bids = AuctionBid.objects.filter(auctionid=auction)
if not auction_bids:
......@@ -46,4 +45,7 @@ class AddToFavoritesForm(forms.ModelForm):
class Meta:
model = UserFavorites
fields = ['userid','auctionid']
widgets = {'auctionid': forms.HiddenInput()}
\ No newline at end of file
widgets = {
'auctionid': forms.HiddenInput(),
'userid': forms.HiddenInput()
}
\ No newline at end of file
......@@ -21,6 +21,7 @@ class Auction(models.Model):
db_table = 'auction'
class AuctionBid(models.Model):
bidno = models.AutoField(primary_key=True)
amount = models.DecimalField(max_digits=15, decimal_places=4)
......@@ -109,6 +110,7 @@ class BoodleUser(models.Model):
db_table = 'boodleuser'
class DjangoAdminLog(models.Model):
action_time = models.DateTimeField()
object_id = models.TextField(blank=True, null=True)
......@@ -164,6 +166,8 @@ class Item(models.Model):
class Meta:
managed = False
db_table = 'item'
def __str__(self):
return self.itemname
class Store(models.Model):
......
......@@ -21,7 +21,7 @@ def homepage(request):
# Filter by auctions scheduled at most a week from now
week_range = datetime.now() + timedelta(days=7)
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)
context = {
......@@ -31,7 +31,7 @@ def homepage(request):
return render(request, "boodlesite/templates/index.html",context)
def auction(request, pk):
def auction(request,pk):
# Current auction ID
auction = Auction.objects.get(pk=pk)
......@@ -39,13 +39,12 @@ def auction(request, pk):
auction_item = auction.itemid
# Auction bids
auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime')
highest_bid = auction_item.floorprice
if auction_bids:
highest_bid = auction_bids[0].amount
# PLACE BID FORM
# PLACE BID FORM AND ADD TO FAVES FORM
form = PlaceBidForm(initial={'auctionid':auction})
if request.method == 'POST':
form = PlaceBidForm(request.POST,initial={'auctionid':auction})
......@@ -58,19 +57,29 @@ def auction(request, pk):
except:
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 = {
'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