November 2015
Beginner to intermediate
840 pages
26h 30m
English
We’ve seen select_related(), prefetch_related(), Q and Prefetch objects, and we know how to profile with queryset.query and connection. It’s time to put all our tools to work.
In our generic class-based views (GCBVs), we have used the model attribute to tell our views which model to fetch. Most GCBVs also allow for the use of the queryset, which enables us to define the queryset used on the model (which now doesn’t need to be set). We can, for instance, use the select_related() method in PostDetail to fetch both the Post object and the User object related by the author field, as shown in Example 26.31.
Example 26.31: Project Code
48 class ...
Read now
Unlock full access