A simple group-by (no count) in Django
        Posted  
        
            by Daniel Quinn
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Daniel Quinn
        
        
        
        Published on 2010-04-23T01:03:56Z
        Indexed on 
            2010/04/23
            6:23 UTC
        
        
        Read the original article
        Hit count: 272
        
If this were raw-SQL, it'd be a no-brainer, but in Django, this is proving to be quite difficult to find. What I want is this really:
SELECT
  user_id
FROM
  django_comments
WHERE
  content_type_id = ? AND
  object_pk = ?
GROUP BY
  user_id
It's those last two lines that're the problem. I'd like to do this the "Django-way" but the only thing I've found is mention of aggregates and annotations, which I don't think solve this issue... do they? If someone could explain this to me, I'd really appreciate it.
© Stack Overflow or respective owner