fi FirmComment objects extra select rang firms_firmcomment rang count

1
2
3
4
5
6
7
8
fi = M.FirmComment.objects.extra(select='rang':'firms_firmcomment.rang','count':'count(1)'}).values('count','rang')
In [59]: fi.query.group_by = ['rang']
In [60]: fi.filter(content_type=ct_firm, object_pk=1366)
#А в результате такая СЮЛИНА:
SELECT (count(1)) AS `count`, (firms_firmcomment.rang) AS `rang` FROM `firms_firmcomment` INNER JOIN `threadedcomments_comment` ON (`firms_firmcomment`.`threadedcomment_ptr_id` = `threadedcomments_comment`.`comment_ptr_id`) INNER JOIN `django_comments` ON (`threadedcomments_comment`.`comment_ptr_id` = `django_comments`.`id`) WHERE (`django_comments`.`object_pk` = 1366 AND `django_comments`.`content_type_id` = 46 ) GROUP BY rang, count(1), firms_firmcomment.rang ORDER BY `threadedcomments_comment`.`tree_path` ASC LIMIT 21