How to do many-to-many Django query to find book with 2 given authors?

后端 未结 4 519
夕颜
夕颜 2020-11-30 02:57

I have a query that requires to filter exactly 2 authors with the ID

Theoretically,

Book.objects.filter(author__id=1, author__id=2). 
4条回答
  •  眼角桃花
    2020-11-30 03:25

    Q objects will help you. Docs

    Book.objects.filter(Q(author__id=1) & Q(author__id=2))
    

提交回复
热议问题