django model foreign key queryset selecting related fields

前端 未结 2 1300
小蘑菇
小蘑菇 2020-12-28 23:19

I am trying to select from the join of the two related tables in DJango as shown below. But I am not able get the field name of the other table.

In SQL

2条回答
  •  無奈伤痛
    2020-12-29 00:08

    phonenumber is a field on person, so you need to pass in person__phonenumber

    m=Membership.objects.filter(person__name='x').values('person','person__phonenumber').
    

提交回复
热议问题