[Django]-Django get data from multiple tables

3👍

You should use select related feature :

Project.objects.select_related().all()

3👍

Why are you using raw SQL? Learn Querysets.
1. Using Querysets:

projects = Project.objects.select_related('leader').all()
for project in projects:
    print project.name, project.leader.user_name

Note: select_related creates join with User1 and saves you extra SQL queries when accessing User1 model

2. get only list of leader and project name.

project_list = Project.objects.select_related('leader')\
                              .values_list('name', 'leader__user_name')

Leave a comment