django model foreign key queryset selecting related fields

前端 未结 2 1286
小蘑菇
小蘑菇 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-28 23:49

    Also if you want a queryset (so not to use values) you can do this:

    m=Membership.objects.filter(person__name="x").select_related('person', depth=1)
    

    Sadly I do not know how to only get one field from that table and still get a queryset.

    0 讨论(0)
  • 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').
    
    0 讨论(0)
提交回复
热议问题