Answer the question
In order to leave comments, you need to log in
How to get posts for current week django queryset?
How to get posts for current week django queryset?
Tried through timedelta but it turns out not what you need. For example today is Monday and I need to get posts only from this week i.e. from this Monday, and if you use timedelta, it turns out that posts are also taken from last week starting from Tuesday
Answer the question
In order to leave comments, you need to log in
You can request data by week number week and iso_year
import datetime
date = datetime.datetime.today()
week = date.strftime("%V")
Entry.objects.filter(pub_date__week=week)
from django.utils.timezone import now
year, week, _ = now().isocalendar()
Entry.objects.filter(pub_date__iso_year=year, pub_date__week=week)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question