Assuming you have this setup:
class UserProfile(models.Model): user = models.ForeignKey(User, related_name='profile') ...
You can use the following related select: Comments.objects.select_related('user__pk','user__profile__pk') and it should do what you want.
You will need to expand the scope of the comments. It is pretty simple. Basically create your own comment app. You can look at django-threadedcomments for inspiration (and, in fact, in a way, this is already the best implementation to use anyway).
Here, the code can be inserted into the django-threaded comment application to make sure that it always uses the associated select (in models.py):
class RelatedCommentManager(CommentManager): def filter(self, *args, **kwargs): return super(RelatedCommentManager, self).select_related('user__pk','user__profile__pk').filter(*args, **kwargs) def exclude(self, *args, **kwargs): return super(RelatedCommentManager, self).select_related('user__pk','user__profile__pk').exclude(*args, **kwargs) def all(self) return super(RelatedCommentManager, self).select_related('user__pk','user__profile__pk').all()
and replace
objects = CommentManager()
from
objects = RelatedCommentManager()
Follow the instructions for integrating threads into your application.
Then in the template, I think you will have to reference .profile instead of .get_profile .
Perhaps Django will automatically detect this value, so get_profile will not generate another db hit as long as .profile is available.