How to add an additional field to a queryset?
- by Mark
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.