在view.py
中Id = [2,3,4,5,6,7,8]
for w in Id:
A = w
Pending = pending(A)
data = {
'Pending': Pending,
}
return render_to_response('dialer_campaign/campaign/list.html', data, context_instance=RequestContext(request))
def pending(campaign_id):
A = Campaign_phonebook.objects.values_list('phonebook_id').filter(campaign_id = campaign_id)
B = Contact.objects.filter(phonebook_id__in=A).count()
C = Subscriber.objects.filter(campaign_id = campaign_id).exclude(status = 1).count()
Result = B - C
return Result
当我添加手动值而不是A时,它会给出结果,但现在我想通过for循环给出值,它不起作用。为什么?有人可以帮助我吗?
我想在模板中做更改吗?
先谢谢..
答案 0 :(得分:2)
将您的数据对象放入列表并渲染到模板
参考以下代码
Id = [2,3,4,5,6,7,8]
pending_list = []
for w in Id:
pending = pending(w)
pending_list.append({'pending': pending})
return render_to_response('dialer_campaign/campaign/list.html', pending_list, context_instance=RequestContext(request))
def pending(campaign_id):
A = Campaign_phonebook.objects.values_list('phonebook_id').filter(campaign_id = campaign_id)
B = Contact.objects.filter(phonebook_id__in=A).count()
C = Subscriber.objects.filter(campaign_id = campaign_id).exclude(status = 1).count()
Result = B - C
return Result
在模板中使用pending_list。在pending_list列表中,您将获得所有待处理对象。