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 @@ ...@@ -67,11 +67,38 @@
<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>
<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 %} {% csrf_token %}
<input type="hidden" name="supporttype" /> {{ addtofavs_form }}
<button type="button" class="btn btn-dark"><input type="submit" value="Add to My Favorites" /> </button> </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"
......
...@@ -41,3 +41,9 @@ class AddItemForm(forms.ModelForm): ...@@ -41,3 +41,9 @@ class AddItemForm(forms.ModelForm):
'itemspecs': _('Item Description'), 'itemspecs': _('Item Description'),
'floorprice': _('Floor Price') '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): ...@@ -103,7 +103,6 @@ class BoodleUser(models.Model):
displayname = models.CharField(max_length=255) displayname = models.CharField(max_length=255)
pword = models.CharField(max_length=255) pword = models.CharField(max_length=255)
username = 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: class Meta:
managed = False managed = False
...@@ -177,7 +176,8 @@ class Store(models.Model): ...@@ -177,7 +176,8 @@ class Store(models.Model):
db_table = 'store' 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') userid = models.ForeignKey(BoodleUser, models.DO_NOTHING, db_column='userid')
auctionid = models.ForeignKey(Auction, models.DO_NOTHING, db_column='auctionid') auctionid = models.ForeignKey(Auction, models.DO_NOTHING, db_column='auctionid')
......
...@@ -45,6 +45,7 @@ def auction(request, pk): ...@@ -45,6 +45,7 @@ def auction(request, pk):
if auction_bids: if auction_bids:
highest_bid = auction_bids[0].amount highest_bid = auction_bids[0].amount
# PLACE BID 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,6 +58,19 @@ def auction(request, pk): ...@@ -57,6 +58,19 @@ def auction(request, 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
context = { context = {
'item_name':auction_item.itemname, 'item_name':auction_item.itemname,
...@@ -66,6 +80,7 @@ def auction(request, pk): ...@@ -66,6 +80,7 @@ def auction(request, pk):
'highest_bid': highest_bid, 'highest_bid': highest_bid,
'auction_end': auction.auctionend, 'auction_end': auction.auctionend,
'form' : form, 'form' : form,
'addtofavs_form': addtofavs_form,
} }
if auction.auctionend < datetime.now(): if auction.auctionend < datetime.now():
...@@ -159,13 +174,3 @@ def profile(request, pk): ...@@ -159,13 +174,3 @@ def profile(request, pk):
} }
return render(request, "boodlesite/templates/profile.html", context) 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