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 withUser1
and saves you extra SQL queries when accessingUser1
model
2. get only list of leader and project name.
project_list = Project.objects.select_related('leader')\
.values_list('name', 'leader__user_name')
Source:stackexchange.com