Hay all, I'm having difficulty accessing the first related object within a template.
I'm using
{{ course.student_set.all[0].get() }}
but its throwing loads of errors. How do i get the first related object?
Thanks
Hay all, I'm having difficulty accessing the first related object within a template.
I'm using
{{ course.student_set.all[0].get() }}
but its throwing loads of errors. How do i get the first related object?
Thanks
{{ course.student_set.all.0 }}
Will do the trick for you, but I wonder why you want to only get the first student from your course in your template.
Try {{ course.student_set.all.0 }}
. Template engine does not allow arbitrary code and method access syntax is different from normal Python code. I recommend reading this overview to understand how templates work