[Django]-Filter models with created date less than today's date

12👍

Use the __lt (less than) filter lookup:

from datetime import datetime

Post.objects.filter(created__lt=datetime.today())

1👍

This should work for posts created earlier than today

from datetime import date
Post.objects.filter(created__lte=date.today())

In case you want to include post’s from today but earlier than right now use:

from datetime import datetime
Post.objects.filter(created__lte=datetime.today())

Leave a comment