Priyatham-sai-chand/auctions/models.py

44 lines
1.8 KiB
Python
Raw Normal View History

2020-10-15 10:18:39 -07:00
from django.contrib.auth.models import AbstractUser
from django.db import models
class User(AbstractUser):
2020-10-19 06:59:55 -07:00
watchlist = models.ManyToManyField('AuctionListing',blank = True,related_name="watchlists")
2020-10-15 10:18:39 -07:00
class AuctionListing(models.Model):
2020-10-19 06:59:55 -07:00
category_choices = (
('Fashion','Fashion'),
('Electronics','Electronics'),
('Home','Home'),
('Sports','Sports'),
('Toys','Toys'),
('Automobile','Automobile'),
('Books','Books'),
('Videogames','Videogames'),
('Other','Other'),
)
2020-10-15 10:18:39 -07:00
title = models.CharField(max_length = 64,primary_key = True)
2020-10-18 09:27:28 -07:00
user = models.ForeignKey(User,on_delete = models.CASCADE)
2020-10-15 10:18:39 -07:00
price = models.DecimalField(max_digits = 10,decimal_places = 2)
desc = models.CharField(max_length = 1000)
2020-10-19 06:59:55 -07:00
picture = models.URLField(default="https://www.riobeauty.co.uk/images/product_image_not_found.gif")
category = models.CharField(max_length = 64,choices=category_choices)
2020-10-18 09:27:28 -07:00
date_added = models.DateTimeField(auto_now_add=True)
2020-10-15 10:18:39 -07:00
def __str__(self):
2020-10-18 09:27:28 -07:00
return f"{self.title}: {self.price},{self.desc},{self.picture},{self.category},{self.date_added}"
2020-10-18 13:06:31 -07:00
class Comment(models.Model):
listing = models.ForeignKey(AuctionListing,on_delete = models.CASCADE,related_name="comments")
user = models.ForeignKey(User,related_name="commited_user",on_delete=models.CASCADE)
body = models.TextField()
date_added = models.DateTimeField(auto_now_add=True)
2020-10-18 09:27:28 -07:00
2020-10-18 13:06:31 -07:00
def __str__(self):
return '%s - %s' % (self.listing.title, self.user)
2020-10-19 06:59:55 -07:00
class Bids(models.Model):
bid_value = models.DecimalField(max_digits = 10,decimal_places = 2)
user = models.ForeignKey(User,on_delete = models.CASCADE, related_name="bidding_user")
listing = models.ForeignKey(AuctionListing, on_delete= models.CASCADE, related_name="bidding_listing")