Creating QuerySet object from last 7 days
Question:
posts = Post.objects.filter(author=member.user, xyz=xyz_id, pub_date >= datetime.datetime.now()-7)
I want to extract all posts by those requires of author and xyz which will be from last 7 days. Results only from last 7 days. I ofc know that this is wrong but I do not have idea how to code it.
Answers:
from datetime import datetime, timedelta
posts = Post.objects.filter(author=member.user, xyz=xzy_id, pub_date__gte=datetime.now()-timedelta(days=7))
posts = Post.objects.filter(author=member.user, xyz=xyz_id, pub_date >= datetime.datetime.now()-7)
I want to extract all posts by those requires of author and xyz which will be from last 7 days. Results only from last 7 days. I ofc know that this is wrong but I do not have idea how to code it.
from datetime import datetime, timedelta
posts = Post.objects.filter(author=member.user, xyz=xzy_id, pub_date__gte=datetime.now()-timedelta(days=7))