开发者

Get entry by week number using Django ORM?

开发者 https://www.devze.com 2022-12-23 02:46 出处:网络
I tried something like: MyModel.objects.filter(year__week=1) It doesn\'t work. For now, I 开发者_StackOverflow中文版calculate the first day and the last day of the week and then use gte and lte, b

I tried something like:

MyModel.objects.filter(year__week=1)

It doesn't work. For now, I 开发者_StackOverflow中文版calculate the first day and the last day of the week and then use gte and lte, but it's less than efficient given that SQL comes with a Week function.


It seems that django DateField doesn't have week attribute, as weel as date object from Python. They have both year and month and also day, but not week attribute. I guess you need to translate week to day range and file a ticket on django website ;-)

0

精彩评论

暂无评论...
验证码 换一张
取 消