Imitating Place Bid feature for add to favorites.

Made a modal and forms.py is a work in progress.
parent 22d9e803
......@@ -67,11 +67,38 @@
<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>
<form method="POST" action="">
<!-- 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 %}
<input type="hidden" name="supporttype" />
<button type="button" class="btn btn-dark"><input type="submit" value="Add to My Favorites" /> </button>
{{ 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 -->
<div class="modal fade" id="placeBidModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
......
......@@ -41,3 +41,9 @@ class AddItemForm(forms.ModelForm):
'itemspecs': _('Item Description'),
'floorprice': _('Floor Price')
}
class AddToFavoritesForm(forms.ModelForm):
class Meta:
model = UserFavorites
fields = ['userid','auctionid']
widgets = {'auctionid': forms.HiddenInput()}
\ No newline at end of file
......@@ -103,7 +103,6 @@ class BoodleUser(models.Model):
displayname = models.CharField(max_length=255)
pword = models.CharField(max_length=255)
username = models.CharField(max_length=255)
favorites = models.ManyToManyField(Auction, related_name='user_favorites', null=True, blank=True)
class Meta:
managed = False
......@@ -177,7 +176,8 @@ class Store(models.Model):
db_table = 'store'
class Userfavorites(models.Model):
class UserFavorites(models.Model):
favid = models.AutoField(primary_key=True)
userid = models.ForeignKey(BoodleUser, models.DO_NOTHING, db_column='userid')
auctionid = models.ForeignKey(Auction, models.DO_NOTHING, db_column='auctionid')
......
......@@ -45,6 +45,7 @@ def auction(request, pk):
if auction_bids:
highest_bid = auction_bids[0].amount
# PLACE BID FORM
form = PlaceBidForm(initial={'auctionid':auction})
if request.method == 'POST':
form = PlaceBidForm(request.POST,initial={'auctionid':auction})
......@@ -57,6 +58,19 @@ 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
context = {
'item_name':auction_item.itemname,
......@@ -66,6 +80,7 @@ def auction(request, pk):
'highest_bid': highest_bid,
'auction_end': auction.auctionend,
'form' : form,
'addtofavs_form': addtofavs_form,
}
if auction.auctionend < datetime.now():
......@@ -159,13 +174,3 @@ def profile(request, pk):
}
return render(request, "boodlesite/templates/profile.html", context)
def favorites(request, pk):
if request.method == 'POST':
favorite = Auction.objects.get(pk=pk)
# user = request.user
current_user = BoodleUser.objects.get(pk=pk)
current_user.favorites.add(favorite)
print("Favorited!")
#messages.add_message(request, messages.INFO, 'Deal Favorited.')
return redirect(f"/auction/{pk}")
\ No newline at end of file
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