I'm just getting started with the new(ish) class-based views, and I am wondering what's the best way to get select_related() in there. Here's my view:
class PostDetailView(DetailView):
model = Post
The post comes from the 'slug' in the URL. This works fine, but, I would like to get select_related() in there to reduce the number of queries.
Specify a queryset
instead of model
:
class PostDetailView(DetailView):
queryset = Post.objects.select_related()
(See the docs).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With