Reputation: 4275
I would like to retrieve all objects form A
class A(models.Model):
date_sent = models.DateTimeField()
for which date_sent is older than 1 day.
I tried:
A(Q((date_sent - datetime.now()).days > 1))
but python tells me that date_sent is not defined.
Upvotes: 0
Views: 87
Reputation: 5613
from datetime import datetime, timedelta
result = A.objects.filter(date_sent__lt=datetime.date.today() - timedelta(days=1))
Upvotes: 1
Reputation: 7889
If A
is the name of your class, I think you have to call A.objects.get
first:
A.objects.get(
Q((date_sent - datetime.now()).days > 1)
)
"Making queries" from the Django documentation
Upvotes: 0