Possible Duplicate:
A left outer reverse select_related in Django?
A BlogPost
has many Comment
s. I want to get a list of BlogPost
s and all their comments.
Thus, I have
BlogPost.objects.filter(my_filter).select_related()
But the ForeignKey is on the Comment
, not the BlogPost
, so the select_related()
doesn't prefetch any comments. Is there a way to get this to work?
I can't reverse the query (Comment.objects...
) because then the other objects that the select_related()
does fetch wouldn't work. I need it to work both ways.
Why won't you fetch the comments and then use regroup template tag to display them:
Then in template: