So i have a model, And i want to filter all models with created date less than today's date .
For example
Class Post(models.Model):
created=model.DateField()
view.py
get_objects_with_date_lessthan_today_date=Post.objects.filter(created=)
In my view i need to filter all objects with created date less than today's date .Please i need help . In going about this logic
Use the __lt (less than) filter lookup:
from datetime import datetime
Post.objects.filter(created__lt=datetime.today())
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())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With