I have a model called 'Projects'.
Projects can be featured. If they are, they will be displayed on the home page (Projects.filter(is_featured=True))
Each project contains several slides. These slides can be featured (Slide.is_featured=True), and contain an Image model which contains the actual image.
In my home page, I would like to display a slideshow in which each slide contains the project name, and the image contained in the featured slide.
I did that by adding a method called 'featured_slide()' in my Project Model, but now I realize that I've been hitting on the DB every time, and I would like to improve that by using the 'select_related' statement.
How can I do that?
Optimally, I would like to have a field like 'featured_slide' to represent the featured slide.
I was thinking of doing something along these lines:
Projects.filter(is_featured=True).annotate(featured_slide='slides__is_featured=True').select_related(slides__image)
I know it can't be that simple (slides__is_featured is not a database field), but you get the idea.