I want to show this piece of data in template table
{u'User1': {'annual_spend__sum': None}, u'User2': {'annual_spend__sum': 80}, u'User3': {'annual_spend__sum': 30}, u'User4': {'annual_spend__sum': None}}
I am not sure how to loop over the data to show it properly can anyone help?
this_user = User.objects.get(id=3)
all_users = User.objects.all()
values = {}
for this_user in all_users:
values[this_user.username] = Lead.objects.filter(assign_to=this_user).exclude(lead_status='CV').aggregate(Sum('annual_spend'))
values.items()
return render(request, 'index.html', {'annual_spend': values})
Updated
def func(request):
from django.template import context
this_user = User.objects.get(id=3)
all_users = User.objects.all()
values = {}
for this_user in all_users:
values[this_user.username] = Lead.objects.filter(assign_to=this_user).exclude(lead_status='CV').aggregate(Sum('annual_spend'))
context = {}
annual_spend__sum_list = []
data = values
for i in data:
annual_spend__sum_list.append(data[i]['annual_spend__sum'])
context['result'] = annual_spend__sum_list
return render(request, "index.html", context)
Template
<ul>
{% for i in result %}
<li>{{ i }}</li>
{% endfor %}
</ul>