Defining Models Database in class based view


The following is a sample from the django website documentation on class based views. The part of interest to me was defining the models database. It seems that in this example this is in the default database. In my application I usually have to use .using(‘database_name’) to connect my model to the correct database. How would this be done in this case?(or is a router a requirement)


from django.http import HttpResponse
from django.views.generic import ListView
from books.models import Book

class BookListView(ListView):
    model = Book

    def head(self, *args, **kwargs):
        last_book = self.get_queryset().latest('publication_date')
        response = HttpResponse(
            # RFC 1123 date format.
            headers={'Last-Modified': last_book.publication_date.strftime('%a, %d %b %Y %H:%M:%S GMT')},
        return response

You’ll be looking to override the get_queryset method.

See Built-in class-based generic views | Django documentation | Django
and Multiple object mixins | Django documentation | Django