November 2015
Beginner to intermediate
840 pages
26h 30m
English
Manager and QuerySet Classes DirectlyIf you find yourself changing all of your views and templates in the same way, it’s worth considering the fact that you can use select_related() and prefetch_related() directly in a manager or queryset. For instance, we could always fetch the related User and Profile objects when fetching Post objects, as shown in Example 26.37.
Example 26.37: Project Code
21 class BasePostManager(models.Manager): 22 23 def get_queryset(self): 24 return ( 25 PostQueryset( 26 self.model, 27 using=self._db, 28 hints=self._hints) 29 .select_related( ...
Read now
Unlock full access