class A:
name = xxx
"""
1 uu1 2
2 uu2 2
"""
class B:
title = xxxx
xx = FK()
"""
1 uu1 2
2 uu2 2
"""
從A表開始查
data = models.A.objects.all()
for item in data:
item.id,item.name, item.b_set.all()
data = models.A.objects.filter() # 3條
data = models.A.objects.filter(b__id=2)
2 data = models.A.objects.filter(b__id=2).values('id','name','b__title')
data = models.A.objects.values('id','name','b__title')
1 n1 None
2 n2 uu1
2 n2 uu2
3 n3 None