Removed favorites_id from userfavorites model. Did inspectdb for this.

But manually created a ManyToManyField under the boodleuser model.
Created a form for auction html file, add to favorites button.
Creating a method in views to add an auction to favorites of the user.
Co-authored-by: 's avatarpinkboheme <pinkboheme@users.noreply.github.com>
parent 92b7a900
......@@ -66,7 +66,12 @@
<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-dark">Add to My favorites</button>
<form method="POST" action="">
{% csrf_token %}
<input type="hidden" name="supporttype" />
<button type="button" class="btn btn-dark"><input type="submit" value="Add to My Favorites" /> </button>
<!-- MODAL FOR BIDDING -->
<div class="modal fade" id="placeBidModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
......
......@@ -103,6 +103,7 @@ 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
......@@ -176,11 +177,11 @@ class Store(models.Model):
db_table = 'store'
class UserFavorites(models.Model):
favoriteid = models.AutoField(primary_key=True)
class Userfavorites(models.Model):
userid = models.ForeignKey(BoodleUser, models.DO_NOTHING, db_column='userid')
auctionid = models.ForeignKey(Auction, models.DO_NOTHING, db_column='auctionid')
class Meta:
managed = False
db_table = 'userfavorites'
unique_together = (('userid', 'auctionid'),)
......@@ -159,3 +159,13 @@ 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