deVOID
deVOID

Reputation: 325

Date filter in django

Filter dates that have not passed

class Distributor(models.Model):
    expire_at = models.DateTimeField()

I want to get the data that has not expired

Upvotes: 0

Views: 41

Answers (2)

Javad
Javad

Reputation: 2098

from datetime import datetime


desired_query = Distributor.objects.filter(expire_at__gt=datetime.now())

The mentioned query in the above code snippet will return Distributor objects have not expired yet.

Upvotes: 1

Faisal Nazik
Faisal Nazik

Reputation: 2863

Here the query would look like if you want the data where expire_at is null

Distributor.objects.filter(expire_at__isnull=True)

isnull() is a method of the QuerySet class and it returns True if the value of the field is null.

Upvotes: 0

Related Questions