html的
{% for task_in in object_list %}
<time>
{%for x in data %}
{%if x.0 is task_in.id %}
{{x.1|timesince}}  ago
{% endif %}
{% endfor %}
</time>
{% endfor %}
这里内部for循环只执行一次,我不明白我哪里出错了。
修改:object_list, listview
中的数据class TaskListView(generic.ListView):
model = task
template_name = 'property/task_list.html'
def get_queryset(self,**kwargs):
prop_id=self.kwargs['pk']
return task.objects.filter(task_type='property',related_to__contains=[prop_id]).order_by('-id')
def get_context_data(self,**kwargs):
context =super(TaskListView,self).get_context_data(**kwargs)
prop_id=self.kwargs['pk']
obj=task.objects.filter(task_type='property',related_to__contains=[prop_id]).order_by('-id')
obj1=[]
obj2=[]
for task_inst in obj:
date_str=task_inst.date_due
format_str='%d-%m-%Y'
date=datetime.datetime.combine(datetime.datetime.strptime(date_str,format_str).date(),
datetime.datetime.strptime(task_inst.time,"%H:%M").time())
obj1.append(date)
obj2.append(task_inst.id)
obj3=zip(obj2,obj1)
context.update({'id':self.kwargs['pk'],'data':obj3})
return context
在输出中,只显示内部for循环中的一个值。任何帮助将不胜感激!