>>> from inyoka.forum.views import * >>> topics = Topic.objects.order_by('-last_post') >>> topics = topics.annotate(p_count=Count('posts')).filter(p_count=1) >>> topics = topics.distinct() >>> topics = topics.values_list('id', flat=True) >>> str(topics.query) 'SELECT DISTINCT `forum_topic`.`id`, `forum_topic`.`last_post_id` FROM `forum_topic` LEFT OUTER JOIN `forum_post` ON ( `forum_topic`.`id` = `forum_post`.`topic_id` ) GROUP BY `forum_topic`.`id` HAVING COUNT(`forum_post`.`id`) = 1 ORDER BY `forum_topic`.`last_post_id` DESC'