How works super().get_queryset() in Django?

I am trying to get a queryset of questions that have publication date before today's date, but I am getting an error in get_queryset raise ImproperlyConfigured(django.core.exceptions.ImproperlyConfigured: IndexView is missing a QuerySet. Define IndexView.model, IndexView.queryset, or override IndexView.get_queryset().

My code:

class IndexView(generic.ListView):
    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'

    def get_queryset(self):
        return super().get_queryset().filter(pub_date__lte=timezone.now())

But this code works:

    def get_queryset(self):
        return Question.objects.filter(pub_date__lte=timezone.now())

What I am doing wrong? Thanks in advance

There is a parent with a get_queryset(), but that queryset does not come out of "thin air": you either should specify a .queryset [Django-doc] or .model attribute [Django-doc], such that Django can construct the basic queryset:

class IndexView(generic.ListView):
    model = Question
    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'

    def get_queryset(self):
        return super().get_queryset().filter(pub_date__lte=timezone.now())

here we however can work with the database clock with Now [Django-doc], and thus don't need to override .get_queryset(…) at all:

from django.db.models.functions import Now


class IndexView(generic.ListView):
    queryset = Question.objects.filter(pub_date__lte=Now())
    template_name = 'polls/index.html'
    context_object_name = 'latest_question_list'
Back to Top