user1403568
user1403568

Reputation: 493

Creating QuerySet object from last 7 days

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.

Upvotes: 29

Views: 11184

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239460

from datetime import datetime, timedelta

posts = Post.objects.filter(author=member.user, xyz=xzy_id, pub_date__gte=datetime.now()-timedelta(days=7))

Upvotes: 54

Related Questions