質問の言い回しは間違っていると思いますが、ここにあります...conference_list.htmlに表示されている会議のリストと参加者の数があります。。タイトルは問題なく表示されます...ただし、参加者の数はすべての会議で同じです。
Conference 1 Attendees 2
Conference 2 Attendees 2
Conference 3 Attendees 2
Conference 4 Attendees 2
会議4は、2人の参加者がいる唯一の会議です。他は異なる量を持っています。
Views.py:
@login_required
def conference_list(request):
try:
session_notification = request.session['notification']
del(request.session['notification'])
except:
session_notification = None
PAGE_SIZE = 20#number of conferences per page
page = int(request.GET.get('page', 1))
upper_bound = page * PAGE_SIZE - 1
lower_bound = (page - 1) * PAGE_SIZE
context = base_context(request)
network = context['network']
conferences = Conference.objects.all()
second = []
result = []
counter = 0
for conference in conferences:
is_attending = False
if counter < lower_bound or counter > upper_bound:
counter += 1
result.append(None)
continue
result_item = {}
result_item['conference'] = conference
result.append(result_item)
counter += 1
attendees = conference.investors.all()
count = attendees.count()
if request.user in attendees:
is_attending = True
context['attendees'] = attendees
context['is_attending'] = is_attending
context['count'] = count
context['current'] = 'conferences'
context['conferences'] = result
return render_to_response('conference_list.html', context, context_instance=RequestContext(request))
レンプレート:
{% for conference in conferences %}
<p>{{ conference.conference.name }}</p><span>{{ count }}</span>
{% endfor %}
なぜこうなった?適切な量を表示できないのはなぜですか?