[英]get_queryset() in MonthArchiveView returns all objects instead objects created only in requested month
Why get_queryset()
from MonthArchiveView returns all objects from my model instead objects created
only in requested month? 为什么
get_queryset()
返回模型中的所有对象,而不是仅在请求的月份中created
对象?
class BudgetMonthlyView(MonthArchiveView):
template_name = 'budget/monthly.html'
model = FinanceData
date_field = "created"
make_object_list = False
allow_future = False
month_format = '%m'
def get_context_data(self, **kwargs):
context = super(BudgetMonthlyView, self).get_context_data(**kwargs)
print(self.get_queryset()) #return all objects from FinanceData model
print(context['object_list']) #works fine
return context
It's just the way that the MonthArchiveView
is implemented. 这就是
MonthArchiveView
的实现方式。 If you look at the source code , you can see that the object_list
is returned by the get_dated_items
method. 如果您查看源代码 ,则可以看到
get_dated_items
方法返回了object_list
。
It's probably implemented this way because the date archive views add other things to the context as well as the object_list
, for example date_list
. 之所以可以这样实现,是因为日期存档视图将其他内容以及
object_list
添加到上下文中,例如date_list
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.