I have a very simple datamodel with a one to many relationship between video and comments
class Video(models.Model):
url = models.URLField(unique=True)
.
For ForeignKey, you can use selected_related():
Comment.objects.select_related('video').all()
It will generate one query only, gathering coments for you as well as videos.
For something more complex (such as M2M), you need an external app such as unjoinify to make optimizations but it uses SQL queries to then put them back in objects.
If you are unconfortable with this (I am), you have some alternatives:
select_related
that works with M2M and reverse relations.