[Answer]-Passing a Query Set to a Template

1👍

You shouldn’t put those queries there at the class level: the ListView doesn’t know about them and won’t pass them anywhere. Instead you should override get_context_data and return them from there.

class ListProject(ListView):
    ...
    def get_context_data(self, *args, **kwargs):
        context = super(ListProject, self).get_context_data(*args, **kwargs)
        context['open_set'] = Project.with_tasks.filter(task__status=0)
        context['closed_set'] = Project.with_tasks.filter(task__status=1)
        return context

Leave a comment