How to add an additional field to a queryset?
        Posted  
        
            by Mark
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Mark
        
        
        
        Published on 2010-05-30T19:02:44Z
        Indexed on 
            2010/05/30
            19:12 UTC
        
        
        Read the original article
        Hit count: 264
        
I've got a list of affiliates (users who have referred someone to the site):
affiliates = User.objects.annotate(referral_count=Count('referrals')).filter(referral_count__gt=0)
And a count of the number of users each affiliate has referred within a time frame:
new_users = User.objects.filter(date_joined__gt=sd, date_joined__lte=ed)
new_referrals = User.objects.filter(referrals__user__in=new_users).annotate(referral_count=Count('referrals'))
How can I do something like new_referrals['affiliate.username'].referral_count from within my template? Note that this is not just a syntax issue, I also need to index new_referrals somehow so that I'm able to do this.
Either this, or if I can somehow add a new_referral_count to the first query, that'd work too.
© Stack Overflow or respective owner