1

Tried looking at other solutions but i cannot resolve this issue. I have a problem where the django template will iterate through {% for cr in Courses %} but will only do so once outputting the multiple lines together. E.g. given a list [['3000', '1', '2458'], ['3000', '0', '2821']], one iteration will be the whole list and not the two items in the list.

In my django template i have:

<table>
        <tr><th>Course</th><th>Payment Status</th><th>Unit</th><th>Action</th></tr>
        {% for course in Comp_Course %}
            <tr><td>{{ course }}</td><td></td><td></td><td></td></tr>
            {% for 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 my views.py

    courses = []
    comp_course = []
    for 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 = []
            for unit in units:
                if unit.webducate_id == payment.course and 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 i have a small issue somewhere but i am struggling. Thanks

2
  • What is the value of courses if you print out the results to console? Commented Jul 24, 2013 at 8:32
  • Sorry @MattWritesCode, please check the solution bellow. Commented Jul 24, 2013 at 11:42

1 Answer 1

2

IMO Courses looks like this:

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

Try this

courses = []
comp_course = []
for 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 = []
        for unit in units:
            if unit.webducate_id == payment.course and 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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.