[Fixed]-Get_queryset() in MonthArchiveView returns all objects instead objects created only in requested month

1👍

It’s just the way that the MonthArchiveView is implemented. If you look at the source code, you can see that the object_list is returned by the get_dated_items method.

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.

0👍

class BudgetMonthlyView(MonthArchiveView):
    template_name = 'budget/monthly.html'
    queryset = FinanceData.objects.all()
    date_field = "created"
    make_object_list = True
    allow_future = False
    month_format = '%m'
    paginate_by = 50
    context_object_name = 'object_list'
    
    def get_context_data(self, **kwargs):
        context = super(BudgetMonthlyView, self).get_context_data(**kwargs)
        month = self.get_month() # get month
        context['month'] = self.queryset.filter(created__month=month) # you can aggregate for this month ' .aggregate(Sum('cost'))['cost__sum'] '
        print(context['object_list']) #works fine
        return context
        

Leave a comment