Reader small image

You're reading from  Becoming an Enterprise Django Developer

Product typeBook
Published inJun 2022
Reading LevelIntermediate
PublisherPackt
ISBN-139781801073639
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Michael Dinder
Michael Dinder
author image
Michael Dinder

Michael Dinder works as a senior backend developer at Cart, Inc. Michael has helped to develop projects for large enterprises such as PayPal and other companies such as Corcoran Pacific Properties, and countless more either directly or indirectly. He has been programming for more than 15 years with a number of different languages and frameworks, with a focus on Python/Django for the past 5+ years.
Read more about Michael Dinder

Right arrow

Using the Prefetch() class

The Prefetch() class that is provided in the django.db.models library is used to control how a prefetch_related() operation is performed. For instance, we will use it to filter and show only vehicles that are of the VehicleModel that equals "Blazer LT". We can also prefetch all related objects when performing filters in this way. To learn about how to use this class in depth, visit https://docs.djangoproject.com/en/4.0/ref/models/querysets/#prefetch-objects.

Use the following subsections to prepare your view class and template for this demonstration. The URL pattern will remain the same as the demonstration found in the Sellers view subsection of this chapter.

Modifying the view

Follow these steps to modify your existing SellersView class for this next exercise:

  1. In your /chapter_10/views.py file, add the following import statement, preferably before the existing import statements:
    # /becoming_a_django_entdev/chapter_10/views.py
    from...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Becoming an Enterprise Django Developer
Published in: Jun 2022Publisher: PacktISBN-13: 9781801073639

Author (1)

author image
Michael Dinder

Michael Dinder works as a senior backend developer at Cart, Inc. Michael has helped to develop projects for large enterprises such as PayPal and other companies such as Corcoran Pacific Properties, and countless more either directly or indirectly. He has been programming for more than 15 years with a number of different languages and frameworks, with a focus on Python/Django for the past 5+ years.
Read more about Michael Dinder