ubuntuusers.de

Unbenannt

Autor:
ostcar
Datum:
27. November 2015 09:12
Code:
1
2
3
4
5
6
7
>>> 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.values_list('id', flat=True)
>>> topics = topics.distinct()
>>> str(topics.query)
'SELECT DISTINCT `forum_topic`.`id`, `forum_topic`.`last_post_id` FROM `forum_topic` LEFT OUTER JOIN `forum_post` T8 ON ( `forum_topic`.`id` = T8.`topic_id` ) GROUP BY `forum_topic`.`id`, `forum_topic`.`title`, `forum_topic`.`slug`, `forum_topic`.`view_count`, `forum_topic`.`sticky`, `forum_topic`.`solved`, `forum_topic`.`locked`, `forum_topic`.`reported`, `forum_topic`.`hidden`, `forum_topic`.`ubuntu_version`, `forum_topic`.`ubuntu_distro`, `forum_topic`.`has_poll`, `forum_topic`.`forum_id`, `forum_topic`.`reporter_id`, `forum_topic`.`report_claimed_by_id`, `forum_topic`.`author_id`, `forum_topic`.`first_post_id`, `forum_topic`.`last_post_id` HAVING COUNT(T8.`id`) = 1 ORDER BY `forum_topic`.`last_post_id` DESC'