I'm trying to write a query in Django for posts older than 24 hours. The Post form contains a DateTime field named Created_at and this field contains the time the post was added.
How do I get all posts older than 24 hours in Django?
I'm trying to write a query in Django for posts older than 24 hours. The Post form contains a DateTime field named Created_at and this field contains the time the post was added.
How do I get all posts older than 24 hours in Django?
You can retrieve the objects with:
from datetime import timedelta
from django.db.models.functions import Now
Post.objects.filter(Created_at__lte=Now()-timedelta(hours=24))