Is it possible to return querysets that return only one object per foreign key?
For instance, I want the to get the latest comments from django_comments, but I only want one comment (the latest comment) per object, i.e., only return the latest comment on an object and exclude all the past comments on that object. I guess this would be similar to a sql group_by on django_comments.content_type and django_comments.object_pk.
++ADDED INFO++
The end goal is to create a list of active comment "threads" displayed/ordered by which thread has the most recent comment, just like your standard discussion board whose topics are listed by recent activity.
I figure the best way to do this would be grabbing the latest comments, and then sorting or grouping them by content type and object_pk so that only one comment (the latest) is returned per related content object. I can then use that comment to get all the info I need, so the word thread is used loosely since I'm really just grabbing a comment and following it's pk's.
The MODEL is django_threadedcomments which extends django_comments with some added fields for trees, children, and parents.
VIEW:
...this returns all comments including all instances of parent
comments = ThreadedComment.objects.all().exclude(is_public='0').order_by("-submit_date")
...and this is ideal
comments = ThreadedComment.objects.all().exclude(is_public='0').order_by("submit_date").[plus sorting logic to exclude multiple instances of the same object_pk and content_type]
TEMPLATE:
{% for comment in comments %}
TITLE: {{comment.content_object.title}}
STARTED BY : {{comment.content_object.user}}
MOST RECENT REPLY : {{comment.user}} on {{comment.submit_date}}
{% endfor %}
Thanks again!