Home > Blockchain >  how to check if a date is expired or not django?
how to check if a date is expired or not django?

Time:07-13

I have a model that contains informations about trips and one field is a DateTimeField() like this:

class Voyage(models.Model):
    voyid = models.CharField(max_length=20, primary_key= True)
    depart = models.CharField(max_length=30)
    destination = models.CharField(max_length=30)
    datedep = models.DateTimeField() #the datedep is the time and date of the trip departure 

And the result is a list of trips so i want to output only the trips that are not expired: (datedep > now), how do i do that?

CodePudding user response:

You can .filter(…) [Django-doc] with Now [Django-doc] for the database timestamp:

from django.db.models.functions import Now

Voyage.objects.filter(datedep__gt=Now())
  • Related