Updated models.py - removed UserFavorites.

Added boodleuser as fk in auctionbid.
The form doesn't POST the bid of the user assigned to it even if we pre assigned a userid to it.
Modified the auction html file to display the user's displayname.
Made boodleuserid a visible field in forms.py.
Co-authored-by: 's avatarpinkboheme <pinkboheme@users.noreply.github.com>
parent 9e42139b
......@@ -66,13 +66,6 @@
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#placeBidModal"
data-whatever="@mdo">Place Bid</button>
<!-- MODAL FOR ADD TO FAVORITES-->
<form action="" method="POST">
{% csrf_token %}
{{ addtofavs_form }}
<input type="submit" value="Add to favorites" name="Submit__favorite">
</form>
<!-- MODAL FOR BIDDING -->
<div class="modal fade" id="placeBidModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
......@@ -113,7 +106,7 @@
{% if auction_bids %}
{% for bid in auction_bids %}
<li><img src="" alt="">
<p>User offered {{ bid.amount }}</p>
<p>{{user_profile}} offered {{ bid.amount }}</p>
<p> &nbsp | &nbsp </p>
<p>{{bid.bidtime | timesince}} ago </p>
......
......@@ -9,8 +9,8 @@ from django.core.exceptions import ValidationError
class PlaceBidForm(forms.ModelForm):
class Meta:
model = AuctionBid
fields = ['amount','auctionid']
widgets = {'auctionid': forms.HiddenInput()}
fields = ['amount', 'boodleuserid', 'auctionid']
widgets = {'auctionid': forms.HiddenInput(), 'boodleuserid': forms.HiddenInput()}
def clean(self):
super().clean()
......@@ -39,13 +39,4 @@ class AddItemForm(forms.ModelForm):
'itemname': _('Item Name'),
'itemspecs': _('Item Description'),
'floorprice': _('Floor Price')
}
class AddToFavoritesForm(forms.ModelForm):
class Meta:
model = UserFavorites
fields = ['userid','auctionid']
widgets = {
'auctionid': forms.HiddenInput(),
'userid': forms.HiddenInput()
}
\ No newline at end of file
......@@ -21,17 +21,20 @@ 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)
bidtime = models.DateTimeField(blank=True, null=True)
auctionid = models.ForeignKey(Auction, models.DO_NOTHING, db_column='auctionid')
boodleuserid = models.ForeignKey('BoodleUser', models.DO_NOTHING, db_column='boodleuserid')
class Meta:
managed = False
db_table = 'auctionbid'
def __str__(self):
return self.boodleuserid
class AuthGroup(models.Model):
name = models.CharField(unique=True, max_length=150)
......@@ -108,7 +111,6 @@ class BoodleUser(models.Model):
class Meta:
managed = False
db_table = 'boodleuser'
class DjangoAdminLog(models.Model):
......@@ -166,8 +168,6 @@ class Item(models.Model):
class Meta:
managed = False
db_table = 'item'
def __str__(self):
return self.itemname
class Store(models.Model):
......@@ -178,14 +178,3 @@ class Store(models.Model):
class Meta:
managed = False
db_table = 'store'
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')
class Meta:
managed = False
db_table = 'userfavorites'
unique_together = (('userid', 'auctionid'),)
......@@ -40,47 +40,32 @@ def auction(request,pk):
# Auction bids
auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime')
highest_bid = auction_item.floorprice
# get boodle user ID
# userid = AuctionBid.objects.filter(userid=pk)
users = BoodleUser.objects.get(userid=3)
userid = users.userid
# getting the user name
#user_profile = users.displayname
if auction_bids:
highest_bid = auction_bids[0].amount
# PLACE BID FORM AND ADD TO FAVES FORM
form = PlaceBidForm(initial={'auctionid':auction})
form = PlaceBidForm(initial={'auctionid':auction, 'boodleuserid':users})
if request.method == 'POST':
form = PlaceBidForm(request.POST,initial={'auctionid':auction})
form = PlaceBidForm(request.POST,initial={'auctionid':auction, 'boodleuserid':users})
if form.is_valid():
try:
amount = form.cleaned_data['amount']
new_bid = AuctionBid(amount=amount,bidtime=datetime.now(),auctionid=auction)
# saves the bid by auctionid, amount, bidtime, boodleuserid
new_bid = AuctionBid(
amount=amount, bidtime=datetime.now(),
auctionid=auction, boodleuserid=userid)
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,
'item_specs': auction_item.itemspecs,
......@@ -88,8 +73,8 @@ def auction(request,pk):
'item_floor_price': auction_item.floorprice,
'highest_bid': highest_bid,
'auction_end': auction.auctionend,
'user_profile': users.displayname,
'form' : form,
'addtofavs_form': addtofavs_form,
}
if auction.auctionend < datetime.now():
......@@ -110,7 +95,6 @@ def tempstore(request): # temp view
context = {
'current_store':current_store #### used for navbar, access to store 1
}
return render(request, "boodlesite/templates/tempstore.html", context)
......
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