Annotate and Aggregate function in django
        Posted  
        
            by 
                thesteve
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by thesteve
        
        
        
        Published on 2011-03-02T23:22:53Z
        Indexed on 
            2011/03/02
            23:24 UTC
        
        
        Read the original article
        Hit count: 465
        
In django I have the following tables and am trying to count the number of votes by item.
class Votes(models.Model):
    user = models.ForeignKey(User)
    item = models.ForeignKey(Item)
class Item(models.Model):
    name = models.CharField()
    description = models.TextField()
I have the following queryset
queryset = Votes.objects.values('item__name').annotate(Count('item'))
that returns a list with item name and view count but not the item object. How can I set it up so that the object is returned instead of just the string value? I have been messing around with Manager and Queryset methods, that the right track? Any advice would be appreciated.
© Stack Overflow or respective owner