python - Django template not iterating through list -


tried looking @ other solutions cannot resolve issue. have problem django template iterate through {% cr in courses %} once outputting multiple lines together. e.g. given list [['3000', '1', '2458'], ['3000', '0', '2821']], 1 iteration whole list , not 2 items in list.

in django template have:

<table>         <tr><th>course</th><th>payment status</th><th>unit</th><th>action</th></tr>         {% course in comp_course %}             <tr><td>{{ course }}</td><td></td><td></td><td></td></tr>             {% cr in courses %}                 {% if course == cr.0 %}                     <tr>                         <td></td>                         <td>                             {% if cr.1 == "1" %}                                 paid                             {% else %}                                 not paid                             {% endif %}                         </td>                         <td>                             {{ cr.2 }}                         </td>                         <td>                         </td>                     </tr>                 {% endif %}             {% endfor %}         {% endfor %}     </table> 

and in views.py

    courses = []     comp_course = []     payment in transactions:         if payment.payment_type == "1":             unit = units.objects.get(webducate_id=str(payment.course))              comp_course.append(str(unit.course.webducate_id))              units = units.objects.filter(course=unit.course)             unit_list = []             unit in units:                 if unit.webducate_id == payment.course , payment.successfull == "1":                     unit_list.append([str(unit.course.webducate_id),'1',str(unit.webducate_id)])                 else:                     unit_list.append([str(unit.course.webducate_id),'0',str(unit.webducate_id)])             courses.append(unit_list)     comp_course = list(set(comp_course))     return render_to_response('student-account.html', {'courses': courses, 'comp_course': comp_course,'message': "", 'transactions': transactions}, context_instance=requestcontext(request)) 

i think have small issue somewhere struggling. thanks

imo courses looks this:

[[[a,b,c],[d,e,f]]]

try this

courses = [] comp_course = [] payment in transactions:     if payment.payment_type == "1":         unit = units.objects.get(webducate_id=str(payment.course))          comp_course.append(str(unit.course.webducate_id))          units = units.objects.filter(course=unit.course)         unit_list = []         unit in units:             if unit.webducate_id == payment.course , payment.successfull == "1":                 courses.append([str(unit.course.webducate_id),'1',str(unit.webducate_id)])             else:                 courses.append([str(unit.course.webducate_id),'0',str(unit.webducate_id)]) comp_course = list(set(comp_course)) return render_to_response('student-account.html', {'courses': courses, 'comp_course': comp_course,'message': "", 'transactions': transactions}, context_instance=requestcontext(request)) 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -