Getting all items less than a month old

倾然丶 夕夏残阳落幕 提交于 2019-12-03 22:26:31

What is your definition of a "month"? 30 days? 31 days? Past that, this should do it:

from datetime import datetime, timedelta
last_month = datetime.today() - timedelta(days=30)
items = Item.objects.filter(my_date__gte=last_month).order_by(...)

Takes advantange of the gte field lookup.

items = Item.objects.filter(created_date__gte=aMonthAgo)

Where aMonthAgo would be calculated by datetime and timedelta.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!