django按时间筛选,今年,去年,上⽉
django登录注册功能today = w()
1 Current year
Order.objects.filter(created_at__ar)
2 Current month
Order.objects.filter(created_at__ar, created_at__h)
3 Last month
last_month = h - 1 h>1 else 12
last_month_year = ar h > last_month ar - 1
Order.objects.filter(created_at__year=last_month_year, created_at__month=last_month)
4 Last year
last_year = ar - 1
Order.objects.filter(created_at__year=last_year)
5 Single Query
As last year + current year includes last month and current month, and all orders>= last_year includes current year, the query is super simple: Order.objects.filter(created_at__year__gte=last_year)
from:[
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论