I am building an auction website, and I need to create an Object that shows us the winner of the auction once the auction has been ended! my models.py
class Auction(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
start_time = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
end_time = models.DateTimeField() #when times up Winner should be created Automatically
start_price = models.DecimalField(verbose_name="Original Price", max_digits=15, decimal_places=1, default=0.0)
current_price = models.DecimalField(verbose_name="Current Price", max_digits=15, decimal_places=1, default=0.0)
next_price = models.DecimalField(verbose_name="Next Price", max_digits=15, decimal_places=1, default=0.0)
step = models.DecimalField(verbose_name="Raise Price", max_digits=15, decimal_places=1, default=0.0)
sold_price = models.DecimalField(verbose_name="Sold Price", max_digits=15, decimal_places=1, blank=True, null=True)
is_active = models.BooleanField(default=True)
is_manual = models.BooleanField(default=True)
def __str__(self):
return self.product.title
class Bid(models.Model):
Types = (
('auto', 'Automatically'),
('user', 'By user own')
)
auction = models.ForeignKey(Auction, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
time = models.DateTimeField(auto_now_add=True)
price = models.DecimalField(verbose_name="Bid Price", max_digits=15, decimal_places=1, default=0.0)
action = models.CharField(max_length=120, default="user", choices=Types)
def __str__(self):
return str(self.price)
class Winner(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
auction = models.ForeignKey(Auction, on_delete=models.CASCADE)
won_price = models.DecimalField(verbose_name="Won Price", max_digits=15, decimal_places=1)
won_time = models.DateTimeField()
def __str__(self):
return self.user.username
For the auction process, I am using Django Channels which means I can create the winner if the auction page has viewers(when WebSocket is on) else I am not able to do that! That's why I have to do it on the back-end
and here's my docker-compose.yml
file(edited):
version: '3'
services:
dbauction:
container_name: mysite
image: postgres:12.2
environment:
POSTGRES_DB: db_mysite
POSTGRES_USER: user
POSTGRES_PASSWORD: mysitepass
volumes:
- postgres_data:/var/lib/postgresql/mysite/
mysiteweb:
container_name: mysiteweb
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- dbauction
links:
- redis:redis
env_file:
- ./.env.dev
redis:
restart: always
image: redis:latest
ports:
- "6379:6379"
volumes:
- redisdata:/data
volumes:
postgres_data:
redisdata: