Issue
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?
Solution
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())
Answered By - Willem Van Onsem
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.