Suppose I have the following SQL query:
SELECT
a.id, ct, 1 as one
FROM article a
LEFT JOIN (
SELECT article_id, count(distinct(tag)) AS ct
FROM article_tag
WHERE tag IN ('football', 'tennis', 'django', 'mma')
GROUP BY article_id
ORDER BY ct
) t ON t.article_id = a.ID
ORDER BY t.ct DESC NULLS LAST
, (a.blog = '
ign.com') DESC NULLS LAST
, rating DESC NULLS LAST;
Now execute it in Django:
Article.objects.raw(query);
According to [Django documentation][1], the queryset will contain the values of `ct` and `one` for each article. However, while it prints the value of `one` correctly, it does not for `ct` and just returns `null`. Is there any way to get `ct` for each article?
Thanks.