Fixed adding of store via form.

Allows user to edit a store's details.
Modified the models (userid as FK for store model).
URL redirection for edit store. Made buttons work in profile.html
Co-authored-by: 's avatarpinkboheme <pinkboheme@users.noreply.github.com>
Co-authored-by: 's avatarChristine <cdeeerrr@users.noreply.github.com>
parent 30d414e5
...@@ -19,15 +19,17 @@ ...@@ -19,15 +19,17 @@
<h4> {{ username }} </h4> <h4> {{ username }} </h4>
</div> </div>
<div class="btn-group profile-element" role="group" aria-label="Basic example"> <div class="btn-group profile-element" role="group" aria-label="Basic example">
{% if storename %} <!--If a user owns a store, they can access the store-->
{% if store %}
<button type="button" class="btn btn-primary"> <button type="button" class="btn btn-primary">
<a href= "{% url 'storeid' storename.storeid %}" > <a href= "{% url 'storeid' store %}" >
My Store My Store
</a> </a>
</button> </button>
<!--If a user does not own a store, they can create a store-->
{% else %} {% else %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#createStoreModal" <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#createStoreModal"
data-whatever="@mdo">Create Store</button> data-whatever="@mdo">Create Store</button>
{% endif %} {% endif %}
<button type="button" class="btn btn-primary">Edit Profile</button> <button type="button" class="btn btn-primary">Edit Profile</button>
...@@ -47,10 +49,6 @@ ...@@ -47,10 +49,6 @@
</a> </a>
<p>{{ id.auctionend }}</p> <p>{{ id.auctionend }}</p>
</div> </div>
{% comment %} <form action="" method="POST">
{% csrf_token %}
<input type="submit" name="remove-auction" value="remove auction">
</form> {% endcomment %}
</div> </div>
{% endfor %} {% endfor %}
......
...@@ -9,13 +9,17 @@ ...@@ -9,13 +9,17 @@
{% block content %} {% block content %}
<div class="store-container"> <div class="store-container">
<div class="store-banner"><img src="https://www.w3schools.com/howto/img_snow_wide.jpg"> <div class="store-banner"><img src="https://www.w3schools.com/howto/img_snow_wide.jpg">
<div class="store-info"> <div class="store-info">
<img src="https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png"> <img src="https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png">
<h1>{{ current_store.storename }}</h1> <h1>{{ current_store.storename }}</h1>
<p>@username</p> <p>@username</p>
<button class="edit-shop-btn" type="button">Edit Shop Info</button> <!-- EDIT STORE STUFF -->
<button class="edit-shop-btn" type="button">
<a href="{% url 'editstoreid' current_store.storeid %}">Edit Store Info</a>
</button>
</div> </div>
</div> </div>
......
{% extends 'boodlesite\templates\base.html' %}
{% load static %}
{% block title %}My Store{% endblock %}
{% block styles %}
{% endblock %}
{% block content %}
<div class="container">
<h1>{{ title }}</h1>
<div class="row">
<div class="col-lg-7 col-md-6">ITEM IMAGE CONTAINER
<div class="item-image-container"></div>
</div>
<div class=" col-lg-5 col-md-6">ITEM FORM CONTAINER
<div class="item-form-container">
<form action="" method="POST">
{% csrf_token %}
{{ form.as_p }}
</div>
<button type="submit" name="Add Item"> Save Changes </button>
</form>
</div>
</div>
</div>
<!-- Form with fields:
[Item name]
[Item Description]
[Floor Price] -->
<!-- Image, if no image add image -->
{% endblock %}
\ No newline at end of file
...@@ -104,7 +104,8 @@ class StartAuctionForm(forms.ModelForm): ...@@ -104,7 +104,8 @@ class StartAuctionForm(forms.ModelForm):
class CreateStoreForm(forms.ModelForm): class CreateStoreForm(forms.ModelForm):
class Meta: class Meta:
model = Store model = Store
fields = ['storename', 'storedesc'] fields = ['storename', 'storedesc', 'userid']
widgets = {'userid': forms.HiddenInput()}
labels = { labels = {
'storename': _('Store Name'), 'storename': _('Store Name'),
......
...@@ -19,10 +19,6 @@ class Auction(models.Model): ...@@ -19,10 +19,6 @@ class Auction(models.Model):
class Meta: class Meta:
managed = False managed = False
db_table = 'auction' db_table = 'auction'
def __str__(self):
return f' {self.auctionid}'
# return f'{type(self.title)} {type(self.auctionid)}'
class AuctionBid(models.Model): class AuctionBid(models.Model):
...@@ -30,15 +26,12 @@ class AuctionBid(models.Model): ...@@ -30,15 +26,12 @@ class AuctionBid(models.Model):
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') 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)
...@@ -111,7 +104,6 @@ class BoodleUser(models.Model): ...@@ -111,7 +104,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)
storeid = models.ForeignKey('Store', models.DO_NOTHING, db_column='storeid', blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
...@@ -173,16 +165,21 @@ class Item(models.Model): ...@@ -173,16 +165,21 @@ class Item(models.Model):
class Meta: class Meta:
managed = False managed = False
db_table = 'item' db_table = 'item'
def __str__(self): def __str__(self):
return '%s' % (self.itemname) return '%s' % (self.itemname)
class Store(models.Model): class Store(models.Model):
storeid = models.AutoField(primary_key=True) storeid = models.AutoField(primary_key=True)
storename = models.CharField(max_length=255) storename = models.CharField(max_length=255)
storedesc = models.CharField(max_length=700) storedesc = models.CharField(max_length=700)
userid = models.ForeignKey(BoodleUser, models.DO_NOTHING, db_column='userid', blank=True, null=True)
class Meta: class Meta:
managed = False managed = False
db_table = 'store' db_table = 'store'
def __str__(self):
return '%s' % (self.storeid)
\ No newline at end of file
...@@ -19,4 +19,5 @@ urlpatterns = [ ...@@ -19,4 +19,5 @@ urlpatterns = [
# this is tempuser profile # this is tempuser profile
path('profile', tempProfile, name='profile'), path('profile', tempProfile, name='profile'),
path('profile/<int:pk>', profile, name='profileid'), path('profile/<int:pk>', profile, name='profileid'),
path('editstore/<int:pk>', editStore, name='editstoreid'),
] ]
\ No newline at end of file
...@@ -125,7 +125,6 @@ def mystore(request, pk): ...@@ -125,7 +125,6 @@ def mystore(request, pk):
'current_store':current_store, 'current_store':current_store,
'store_items':store_items, 'store_items':store_items,
'form':form 'form':form
} }
return render(request, "boodlesite/templates/store.html", context) return render(request, "boodlesite/templates/store.html", context)
...@@ -154,7 +153,7 @@ def addItem(request, pk): ...@@ -154,7 +153,7 @@ def addItem(request, pk):
def editItem(request, pk): def editItem(request, pk):
item = Item.objects.get(itemid=pk) item = Item.objects.get(itemid=pk)
current_store = item.storeid.storeid current_store = item.storeid
form = AddItemForm(instance=item) form = AddItemForm(instance=item)
if request.method == 'POST': if request.method == 'POST':
...@@ -178,7 +177,7 @@ def startAuction(request, pk): ...@@ -178,7 +177,7 @@ def startAuction(request, pk):
# get items under this store # get items under this store
store_items = Item.objects.filter(storeid=pk) store_items = Item.objects.filter(storeid=pk)
# Current userid, change as per ⭐ whoever is logged in # Current userid, change as per ⭐ whoever is logged in
user = BoodleUser.objects.get(userid=1) user = BoodleUser.objects.get(userid=3)
userid = user.userid userid = user.userid
# temp: all auctions # temp: all auctions
...@@ -246,19 +245,35 @@ def profile(request, pk): ...@@ -246,19 +245,35 @@ def profile(request, pk):
# 🔥Current Store, pk here is the storeid # 🔥Current Store, pk here is the storeid
current_user = BoodleUser.objects.get(pk=pk) current_user = BoodleUser.objects.get(pk=pk)
form = CreateStoreForm() form = CreateStoreForm(initial={'userid':pk})
current_store = Store.objects.filter(userid=current_user.userid)
current_storeid = None
for i in current_store:
current_storeid = i
if request.method == 'POST': if request.method == 'POST':
form = CreateStoreForm(request.POST) form = CreateStoreForm(request.POST, initial={'userid':pk})
# putting a default value
if form.is_valid(): if form.is_valid():
form.save() form.save()
return redirect('userid', pk=pk) return redirect('profileid', pk=pk)
# 🔥 # 🔥
# checks if userid exists in store
# if current_user.userid in Store.objects.get():
# if current_user:
# current_store = Store.objects.filter(userid=pk)
# # current_store = Store.objects.get(pk=pk)
# # if the current store exists, it will be the pk the
# else:
# current_store.storeid = None # if current store doesnt exist (no user)
context = { context = {
'displayname': current_user.displayname, 'displayname': current_user.displayname,
'username':current_user.username, 'username': current_user.username,
'storename':current_user.storeid, 'store': current_storeid,
'bidsByUser' : bidsByUser, 'bidsByUser' : bidsByUser,
'auctionsOfUser': auctionsOfUser, 'auctionsOfUser': auctionsOfUser,
'auctions': auctions, 'auctions': auctions,
...@@ -267,3 +282,22 @@ def profile(request, pk): ...@@ -267,3 +282,22 @@ def profile(request, pk):
} }
return render(request, "boodlesite/templates/profile.html", context) return render(request, "boodlesite/templates/profile.html", context)
def editStore(request, pk):
store= Store.objects.get(storeid=pk)
current_store = store.storeid
form = CreateStoreForm(instance=store)
if request.method == 'POST':
form = CreateStoreForm(request.POST, instance=store)
if form.is_valid():
form.save()
return redirect('storeid', pk=current_store)
context = {
'form': form,
'title': 'Edit Store Information'
}
return render(request, "boodlesite/templates/storeForm.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