Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get first related object in template

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?

like image 996
dotty Avatar asked Feb 08 '10 11:02

dotty


1 Answers

{{ 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.

like image 116
Will Hardy Avatar answered Nov 15 '22 10:11

Will Hardy