Django Tutorial page 4, Amend Views section

This section states: “Each generic view needs to know what model it will be acting upon. This is provided using the model attribute.”, right after the code example: a definition of a ListView based class, not using the aforementioned attribute.

class IndexView(generic.ListView):
    # Where's 'model'?
    template_name = 'polls/index.html' 
    context_object_name = 'latest_question_list'

    def get_queryset(self):
        """Return the last five published questions."""
        return Question.objects.order_by('-pub_date')[:5]


class DetailView(generic.DetailView):
    model = Question
    ...

* Each generic view needs to know...

I know it has a query inside a method, though, so maybe the text could be clearer, like “…using either a ‘model’ attribute, or a query”.

What am I missing?
In this case particularly, how does one know in advance that “This is provided by using the ‘model’ attribute.” doesn’t mean only that?

For what it’s worth, I agree with you.

The model to be used is specified using either the model or queryset attribute, or the get_queryset method.

I don’t believe you’re missing anything.

1 Like

I’ve just found a topic that explains just that: Built-in class-based generic views | Django documentation | Django

Django’s docs seem to be built on this kind of approach, always teasing the reader with something new or not yet so clear. I don’t know, it either might encourage searching around, or get quite confusing.