views:

16

answers:

1

if a have a declaration like

 def inside_classroom(request,classname):


    theclass = Classroom.objects.get(classname = classname)
    members = theclass.members.all()
c = Courses.objects.filter(classroom = theclass)


return render_to_response('classroom/inside_classroom.html', {
    'theclass': theclass,
    'c':c,
    'members':members, 

    }, 
    context_instance=RequestContext(request)) 

and i want to display all the members(of a class) in a template, how should i do it??

if i write:

{{theclass.members.all}}

the output is an empty list(though the class has some members)

How should the elements of a m2m table be displayed in a template? thanks!

A: 

You should put members in the Context and in the template then iterate over the all the members, eg.

{% for member in members %}
   {{ member.name }}<br />
   {{ member.xxxx }}
{% endfor %}
lazerscience
yep. i have it in my context, and tryed to iterate, but it shows me nothing :)
dana
can you post the view here?
lazerscience
i've edited now, thanks so much for interest, Bernhard! :)
dana
Are you sure it doesn't bail out at the except block? Getting the class and the members after the try...except again shouldnt be necessary because it's always done in the try.. maybe you can put a `print members` before the last return and see whats outputted on the console!
lazerscience
i've removed the 'try'-'except' part and still no result. Though it seems 'trivial',something goes wrong. i'll review the code, i guess it is my mistake out there:)
dana