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,12 +19,14 @@
<h4> {{ username }} </h4>
</div>
<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">
<a href= "{% url 'storeid' storename.storeid %}" >
<a href= "{% url 'storeid' store %}" >
My Store
</a>
</button>
<!--If a user does not own a store, they can create a store-->
{% else %}
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#createStoreModal"
data-whatever="@mdo">Create Store</button>
......@@ -47,10 +49,6 @@
</a>
<p>{{ id.auctionend }}</p>
</div>
{% comment %} <form action="" method="POST">
{% csrf_token %}
<input type="submit" name="remove-auction" value="remove auction">
</form> {% endcomment %}
</div>
{% endfor %}
......
......@@ -9,13 +9,17 @@
{% block content %}
<div class="store-container">
<div class="store-banner"><img src="https://www.w3schools.com/howto/img_snow_wide.jpg">
<div class="store-info">
<img src="https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png">
<h1>{{ current_store.storename }}</h1>
<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>
......
{% 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):
class CreateStoreForm(forms.ModelForm):
class Meta:
model = Store
fields = ['storename', 'storedesc']
fields = ['storename', 'storedesc', 'userid']
widgets = {'userid': forms.HiddenInput()}
labels = {
'storename': _('Store Name'),
......
......@@ -20,25 +20,18 @@ class Auction(models.Model):
managed = False
db_table = 'auction'
def __str__(self):
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
db_table = 'auctionbid'
# def __str__(self):
# return self.boodleuserid
class AuthGroup(models.Model):
name = models.CharField(unique=True, max_length=150)
......@@ -111,7 +104,6 @@ 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
......@@ -178,11 +170,16 @@ class Item(models.Model):
return '%s' % (self.itemname)
class Store(models.Model):
storeid = models.AutoField(primary_key=True)
storename = models.CharField(max_length=255)
storedesc = models.CharField(max_length=700)
userid = models.ForeignKey(BoodleUser, models.DO_NOTHING, db_column='userid', blank=True, null=True)
class Meta:
managed = False
db_table = 'store'
def __str__(self):
return '%s' % (self.storeid)
\ No newline at end of file
......@@ -19,4 +19,5 @@ urlpatterns = [
# this is tempuser profile
path('profile', tempProfile, name='profile'),
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):
'current_store':current_store,
'store_items':store_items,
'form':form
}
return render(request, "boodlesite/templates/store.html", context)
......@@ -154,7 +153,7 @@ def addItem(request, pk):
def editItem(request, pk):
item = Item.objects.get(itemid=pk)
current_store = item.storeid.storeid
current_store = item.storeid
form = AddItemForm(instance=item)
if request.method == 'POST':
......@@ -178,7 +177,7 @@ def startAuction(request, pk):
# get items under this store
store_items = Item.objects.filter(storeid=pk)
# Current userid, change as per ⭐ whoever is logged in
user = BoodleUser.objects.get(userid=1)
user = BoodleUser.objects.get(userid=3)
userid = user.userid
# temp: all auctions
......@@ -246,19 +245,35 @@ def profile(request, pk):
# 🔥Current Store, pk here is the storeid
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':
form = CreateStoreForm(request.POST)
form = CreateStoreForm(request.POST, initial={'userid':pk})
# putting a default value
if form.is_valid():
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 = {
'displayname': current_user.displayname,
'username':current_user.username,
'storename':current_user.storeid,
'username': current_user.username,
'store': current_storeid,
'bidsByUser' : bidsByUser,
'auctionsOfUser': auctionsOfUser,
'auctions': auctions,
......@@ -267,3 +282,22 @@ def profile(request, pk):
}
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