表查询过滤

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

你可能感兴趣的:(表查询过滤)