0

my projects is bidding site, i wanted to close the bid after some specific date. but i don't know how to implement it. please any one suggest me anything

models.py

    class products(models.Model):
        produtname=models.CharField(max_length=255)
        productdesc=models.CharField(max_length=255)
        amount=models.FloatField()
        image=models.ImageField(upload_to='pics')
        featured=models.BooleanField(default=False)
        enddate=models.DateTimeField()

after the end date I wanted to add the details to the another model automatically another model which has product id and user id

Laksh M
  • 1
  • 4

3 Answers3

0

Simply don't have a soldout field; instead you can just filter for products whose end date is later than today:

from django.utils.timezone import now
# ...
products.objects.filter(enddate__gt=now())
AKX
  • 152,115
  • 15
  • 115
  • 172
  • A product can have enddate greater than today and soldout as True as well. In other words, a product can be sold out before enddate. – Krishna Jun 19 '21 at 13:52
  • bro but at last i need set it to orders table for the last person bidded. i wanted to make as realtime but if i do this i can get the product but making orders will not be realtime it will occur only when some fuction is called – Laksh M Jun 19 '21 at 14:14
0

One way to do it is to make soldout a computed @property instead of a Django field. You'll lose the ability to set it manually (however this still can be achieved with another field) and to query it with the ORM directly (but can be done as in @AKX answer).

class products(models.Model):
    ...
    @property
    def soldout(self):
        return self.enddate > now()
Alexandr Tatarinov
  • 3,946
  • 1
  • 15
  • 30
0

In addition to soldout field you can add a computed property expired in your Data Model. Whenever you need to access the products available for bidding you can use not (expired or soldout).

Edit #1(add code)

Add a new field in your Model

@property
def expired(self):
    return self.enddate > now()

While retrieving.

products.objects.exclude(expired=True, soldout=True)
Krishna
  • 6,107
  • 2
  • 40
  • 43