Distinguished between my store and create store.

Created a form for CreateStore. Form not showing up in modal. Updated the SQL file.
Co-authored-by: 's avatarpinkboheme <pinkboheme@users.noreply.github.com>
parent aa0a3fd1
......@@ -19,7 +19,17 @@
<h4> {{ username }} </h4>
</div>
<div class="btn-group profile-element" role="group" aria-label="Basic example">
<button type="button" class="btn btn-primary">My Store</button>
{% if storename %}
<button type="button" class="btn btn-primary">
<a href= "{% url 'storeid' storename.storeid %}" >
My Store
</a>
</button>
{% else %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#createStoreModal"
data-whatever="@mdo">Create Store</button>
{% endif %}
<button type="button" class="btn btn-primary">Edit Profile</button>
</div>
</div>
......@@ -50,4 +60,35 @@
</div>
</div>
<!-- modal -->
<div class="modal fade" id="createStoreModal" 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">Create {{displayname}}'s Store</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 createstore">
<h5>Current Highest Bid: </h5>
<h3>PHP {{highest_bid}}</h3>
{% csrf_token %}
{{ 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>
{% endblock %}
......@@ -100,3 +100,13 @@ class StartAuctionForm(forms.ModelForm):
for auc in auctions:
if auc.itemid == auctioned_item:
raise ValidationError('Auction Already Exists, pick another Item')
class CreateStoreForm(forms.ModelForm):
class Meta:
model = Store
fields = ['storename', 'storedesc']
labels = {
'storename': _('Store Name'),
'storedesc': _('Store Description')
}
\ No newline at end of file
......@@ -24,12 +24,13 @@ class Auction(models.Model):
return f' {self.auctionid}'
# return f'{type(self.title)} {type(self.auctionid)}'
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')
boodleuserid = models.ForeignKey('Boodleuser', models.DO_NOTHING, db_column='boodleuserid')
class Meta:
managed = False
......@@ -110,6 +111,7 @@ class BoodleUser(models.Model):
displayname = models.CharField(max_length=255)
pword = models.CharField(max_length=255)
username = models.CharField(max_length=255)
storeid = models.ForeignKey('Store', models.DO_NOTHING, db_column='storeid', blank=True, null=True)
class Meta:
managed = False
......
......@@ -42,7 +42,7 @@ def auction(request,pk):
highest_bid = auction_item.floorprice
## ⭐ the user that is logged in
users = BoodleUser.objects.get(userid=1)
users = BoodleUser.objects.get(userid=3)
userid = users.userid
if auction_bids:
......@@ -225,15 +225,9 @@ def profile(request, pk):
current_user = BoodleUser.objects.get(pk=pk)
#auction bid user id = 3 --> bids user made --> know auctions g
## ⭐ the user that is logged in
bidsByUser = AuctionBid.objects.filter(boodleuserid=1).distinct('auctionid')
bidsByUser = AuctionBid.objects.filter(boodleuserid=3).distinct('auctionid')
auctionsOfUser = Auction.objects.all().distinct('auctionid')
# for auction in auctionsOfUser:
# print(auction)
# print(auction.title)
# print(auction.auctionid)
#Is of auctions (FK) in AuctionBid objects
idsOfAuction = []
for bid in bidsByUser:
......@@ -241,32 +235,32 @@ def profile(request, pk):
if bid.auctionid == auction:
idsOfAuction.append(bid.auctionid)
# print(auction.title)
# print(bid.auctionid)
# print("===============") #divider between auctions :3
print("These are the distinct auction IDs: ", idsOfAuction)
# print("These are the distinct auction IDs: ", idsOfAuction)
#💫auctionsOfUser = Auction.objects.all().distinct('auctionid')
# get existing auctions for user's bids
auctions = Auction.objects.all()
# for auction in auctionsOfUser:
# print(auction)
# for bid in bidsByUser:
# for auction in auctionsOfUser:
# if bid.auctionid == auction:
# 🔥Current Store, pk here is the storeid
current_user = BoodleUser.objects.get(pk=pk)
form = CreateStoreForm()
for i in idsOfAuction:
print(i)
if request.method == 'POST':
form = CreateStoreForm(request.POST)
if form.is_valid():
form.save()
return redirect('userid', pk=pk)
# 🔥
context = {
'displayname': current_user.displayname,
'username':current_user.username,
'storename':current_user.storeid,
'bidsByUser' : bidsByUser,
'auctionsOfUser': auctionsOfUser,
'auctions': auctions,
'idsOfAuction': idsOfAuction,
'createStoreForm': form,
}
return render(request, "boodlesite/templates/profile.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