Parsing through django queryset output without duplication -
i have 3 tables students,colleges , courses , have done bring together query returns each pupil , college , courses registered. in output each pupil there multiple records registered multiple courses pupil details , colleage details same. i'm executing raw sql in case. need display on template in below format.
student name, college - course1 - course2 - course3
here query,
cursor=connection.cursor() result=cursor.execute('''select s.student_id, s.student_name, c.college_id, c.college_name, cs.course_id, cs.course_name, pupil s inner bring together college c on s.student_id=c.college_id inner bring together course of study cs on s.student_id=cs.course_id''') please help.
if using mysql can utilize group_contact should utilize django's orm this. in template should like:
{% pupil in students %} <tr> <td> {{ pupil }} </td> <td> {{ student.colleges | join:', ' }} </td> <td> {{ student.course | join:', ' }} </td> </tr> {% endfor %} of course of study can utilize select_related lower number of sql queries made.
django django-models
No comments:
Post a Comment