Created models for item and auctionbid.

Created foreign keys but item as a fk doesn't seem to work.
When there wasn't any fk, site seemed to work just fine.
parent f46c6a9c
...@@ -43,15 +43,16 @@ ...@@ -43,15 +43,16 @@
product info div product info div
<div class="product-info" style="border: 2px dotted black;"> <div class="product-info" style="border: 2px dotted black;">
{% for item in items %}
<h2>{{ item.itemname }}</h2>
<h2>Product Name</h2> <h4>{{ item.itemspecs }}</h4>
<h4>Product Specifications</h4>
<p>description description description <p>description description description
description description description description description description
description description description description description description
description description description description description description
description description description</p> description description description</p>
{% endfor %}
</div> </div>
<button class="btn-place-bid">Place Bid</button> <button class="btn-place-bid">Place Bid</button>
......
# Generated by Django 4.0.3 on 2022-03-16 14:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='AuctionBid',
fields=[
('bidno', models.AutoField(primary_key=True, serialize=False)),
('amount', models.FloatField()),
('bidtime', models.DateTimeField()),
],
options={
'db_table': 'auction_bid',
'managed': False,
},
),
migrations.CreateModel(
name='Item',
fields=[
('itemid', models.AutoField(primary_key=True, serialize=False)),
('itemname', models.CharField(max_length=255)),
('itemspecs', models.CharField(max_length=700)),
('floorprice', models.FloatField()),
('sellprice', models.FloatField()),
],
options={
'db_table': 'item',
'managed': False,
},
),
]
...@@ -7,6 +7,15 @@ ...@@ -7,6 +7,15 @@
# Feel free to rename the models, but don't rename db_table values or field names. # Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models from django.db import models
class Item(models.Model):
itemid = models.AutoField(primary_key=True)
itemname = models.CharField(max_length=255)
itemspecs = models.CharField(max_length=700)
floorprice = models.FloatField()
sellprice = models.FloatField()
class Meta:
managed = False
db_table = 'item'
class Auction(models.Model): class Auction(models.Model):
auctionid = models.AutoField(primary_key=True) auctionid = models.AutoField(primary_key=True)
...@@ -14,7 +23,18 @@ class Auction(models.Model): ...@@ -14,7 +23,18 @@ class Auction(models.Model):
info = models.CharField(max_length=255) info = models.CharField(max_length=255)
auctionstart = models.DateTimeField() auctionstart = models.DateTimeField()
auctionend = models.DateTimeField() auctionend = models.DateTimeField()
item = models.ForeignKey(Item, on_delete=models.CASCADE)
class Meta: class Meta:
managed = False managed = False
db_table = 'auction' db_table = 'auction'
class AuctionBid(models.Model):
bidno = models.AutoField(primary_key=True)
amount = models.FloatField()
bidtime = models.DateTimeField()
auction = models.ForeignKey(Auction, on_delete=models.CASCADE)
class Meta:
managed = False
db_table = 'auction_bid'
\ No newline at end of file
...@@ -31,19 +31,22 @@ def auction(request, pk): ...@@ -31,19 +31,22 @@ def auction(request, pk):
# Current auction ID # Current auction ID
auction = Auction.objects.get(pk=pk) auction = Auction.objects.get(pk=pk)
# to display item name, information
items = Item.objects.all()
#items = Item.objects.values_list('itemname', 'itemspecs')
for item in items:
print(item)
# print('auction', pk, auction) # print('auction', pk, auction)
# print(auction.title,auction.info) # print(auction.title,auction.info)
context = {
'items': items
}
if auction.auctionend < datetime.now(): if auction.auctionend < datetime.now():
return HttpResponse("This auction has already passed.") return HttpResponse("This auction has already passed.")
elif auction.auctionstart > datetime.now(): elif auction.auctionstart > datetime.now():
return HttpResponse("This auction has not yet started.") return HttpResponse("This auction has not yet started.")
else: else:
return render(request, "boodlesite/templates/auction.html") return render(request, "boodlesite/templates/auction.html", context)
\ No newline at end of file
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