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
...@@ -67,13 +67,6 @@ ...@@ -67,13 +67,6 @@
<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>
<!-- 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 --> <!-- 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"
aria-hidden="true"> aria-hidden="true">
...@@ -113,7 +106,7 @@ ...@@ -113,7 +106,7 @@
{% if auction_bids %} {% if auction_bids %}
{% for bid in auction_bids %} {% for bid in auction_bids %}
<li><img src="" alt=""> <li><img src="" alt="">
<p>User offered {{ bid.amount }}</p> <p>{{user_profile}} offered {{ bid.amount }}</p>
<p> &nbsp | &nbsp </p> <p> &nbsp | &nbsp </p>
<p>{{bid.bidtime | timesince}} ago </p> <p>{{bid.bidtime | timesince}} ago </p>
......
...@@ -9,8 +9,8 @@ from django.core.exceptions import ValidationError ...@@ -9,8 +9,8 @@ from django.core.exceptions import ValidationError
class PlaceBidForm(forms.ModelForm): class PlaceBidForm(forms.ModelForm):
class Meta: class Meta:
model = AuctionBid model = AuctionBid
fields = ['amount','auctionid'] fields = ['amount', 'boodleuserid', 'auctionid']
widgets = {'auctionid': forms.HiddenInput()} widgets = {'auctionid': forms.HiddenInput(), 'boodleuserid': forms.HiddenInput()}
def clean(self): def clean(self):
super().clean() super().clean()
...@@ -40,12 +40,3 @@ class AddItemForm(forms.ModelForm): ...@@ -40,12 +40,3 @@ class AddItemForm(forms.ModelForm):
'itemspecs': _('Item Description'), 'itemspecs': _('Item Description'),
'floorprice': _('Floor Price') 'floorprice': _('Floor Price')
} }
\ No newline at end of file
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): ...@@ -21,17 +21,20 @@ class Auction(models.Model):
db_table = 'auction' db_table = 'auction'
class AuctionBid(models.Model): class AuctionBid(models.Model):
bidno = models.AutoField(primary_key=True) bidno = models.AutoField(primary_key=True)
amount = models.DecimalField(max_digits=15, decimal_places=4) amount = models.DecimalField(max_digits=15, decimal_places=4)
bidtime = models.DateTimeField(blank=True, null=True) bidtime = models.DateTimeField(blank=True, null=True)
auctionid = models.ForeignKey(Auction, models.DO_NOTHING, db_column='auctionid') auctionid = models.ForeignKey(Auction, models.DO_NOTHING, db_column='auctionid')
boodleuserid = models.ForeignKey('BoodleUser', models.DO_NOTHING, db_column='boodleuserid')
class Meta: class Meta:
managed = False managed = False
db_table = 'auctionbid' db_table = 'auctionbid'
def __str__(self):
return self.boodleuserid
class AuthGroup(models.Model): class AuthGroup(models.Model):
name = models.CharField(unique=True, max_length=150) name = models.CharField(unique=True, max_length=150)
...@@ -110,7 +113,6 @@ class BoodleUser(models.Model): ...@@ -110,7 +113,6 @@ class BoodleUser(models.Model):
db_table = 'boodleuser' db_table = 'boodleuser'
class DjangoAdminLog(models.Model): class DjangoAdminLog(models.Model):
action_time = models.DateTimeField() action_time = models.DateTimeField()
object_id = models.TextField(blank=True, null=True) object_id = models.TextField(blank=True, null=True)
...@@ -166,8 +168,6 @@ class Item(models.Model): ...@@ -166,8 +168,6 @@ class Item(models.Model):
class Meta: class Meta:
managed = False managed = False
db_table = 'item' db_table = 'item'
def __str__(self):
return self.itemname
class Store(models.Model): class Store(models.Model):
...@@ -178,14 +178,3 @@ class Store(models.Model): ...@@ -178,14 +178,3 @@ class Store(models.Model):
class Meta: class Meta:
managed = False managed = False
db_table = 'store' 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): ...@@ -40,47 +40,32 @@ def auction(request,pk):
# Auction bids # Auction bids
auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime') auction_bids = AuctionBid.objects.filter(auctionid=pk).order_by('-bidtime')
highest_bid = auction_item.floorprice 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: if auction_bids:
highest_bid = auction_bids[0].amount highest_bid = auction_bids[0].amount
# PLACE BID FORM AND ADD TO FAVES FORM # PLACE BID FORM AND ADD TO FAVES FORM
form = PlaceBidForm(initial={'auctionid':auction}) form = PlaceBidForm(initial={'auctionid':auction, 'boodleuserid':users})
if request.method == 'POST': if request.method == 'POST':
form = PlaceBidForm(request.POST,initial={'auctionid':auction}) form = PlaceBidForm(request.POST,initial={'auctionid':auction, 'boodleuserid':users})
if form.is_valid(): if form.is_valid():
try: try:
amount = form.cleaned_data['amount'] 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() new_bid.save()
return redirect(f"/auction/{pk}") return redirect(f"/auction/{pk}")
except: except:
pass 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 = { context = {
'item_name':auction_item.itemname, 'item_name':auction_item.itemname,
'item_specs': auction_item.itemspecs, 'item_specs': auction_item.itemspecs,
...@@ -88,8 +73,8 @@ def auction(request,pk): ...@@ -88,8 +73,8 @@ def auction(request,pk):
'item_floor_price': auction_item.floorprice, 'item_floor_price': auction_item.floorprice,
'highest_bid': highest_bid, 'highest_bid': highest_bid,
'auction_end': auction.auctionend, 'auction_end': auction.auctionend,
'user_profile': users.displayname,
'form' : form, 'form' : form,
'addtofavs_form': addtofavs_form,
} }
if auction.auctionend < datetime.now(): if auction.auctionend < datetime.now():
...@@ -110,7 +95,6 @@ def tempstore(request): # temp view ...@@ -110,7 +95,6 @@ def tempstore(request): # temp view
context = { context = {
'current_store':current_store #### used for navbar, access to store 1 'current_store':current_store #### used for navbar, access to store 1
} }
return render(request, "boodlesite/templates/tempstore.html", context) 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