December 2016
Beginner to intermediate
694 pages
14h 2m
English
Now let's take a closer look at the model argument we've been using all along. The model argument, which specifies the database model that the view will operate upon, is available on all the generic views that operate on a single object or a collection of objects. However, the model argument is not the only way to specify the objects that the view will operate upon-you can also specify the list of objects using the queryset argument:
from django.views.generic import DetailView
from books.models import Publisher
class PublisherDetail(DetailView):
context_object_name = 'publisher'
queryset = Publisher.objects.all()
Specifying model = Publisher is really just shorthand for saying queryset = Publisher.objects.all(). However, ...
Read now
Unlock full access