29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
|
from django.contrib.auth.models import AbstractUser
|
||
|
from django.db import models
|
||
|
|
||
|
class User(AbstractUser):
|
||
|
pass
|
||
|
|
||
|
class AuctionListing(models.Model):
|
||
|
title = models.CharField(max_length = 64,primary_key = True)
|
||
|
user = models.ForeignKey(User,on_delete = models.CASCADE)
|
||
|
price = models.DecimalField(max_digits = 10,decimal_places = 2)
|
||
|
desc = models.CharField(max_length = 1000)
|
||
|
picture = models.URLField(null=True)
|
||
|
category = models.CharField(max_length = 64)
|
||
|
date_added = models.DateTimeField(auto_now_add=True)
|
||
|
watchlist = models.ManyToManyField(User,blank = True,related_name="watchlist")
|
||
|
|
||
|
def __str__(self):
|
||
|
return f"{self.title}: {self.price},{self.desc},{self.picture},{self.category},{self.date_added}"
|
||
|
|
||
|
|
||
|
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)
|
||
|
|
||
|
def __str__(self):
|
||
|
return '%s - %s' % (self.listing.title, self.user)
|