Django select_related filter

前端 未结 1 500
臣服心动
臣服心动 2021-02-07 08:45

I have the following Django models.

class A(models.Model):
    tmp = models.ForeignKey(B)
    active = models.BooleanField()

class B(models.Model):
    active =         


        
1条回答
  •  北海茫月
    2021-02-07 09:29

    The same as you would with any other related field, with a __ lookup..

    A.objects.select_related(B).filter(active=True, tmp__active=True, tmp__archived=False)
    

    Using select related doesn't change anything here, its purpose is about what information is returned with the results, it has no effect on filtering at all.

    0 讨论(0)
提交回复
热议问题