How to use OR using Django's model filter system?

后端 未结 1 879
清歌不尽
清歌不尽 2020-12-30 19:34

It seems that Django\'s object model filter method automatically uses the AND SQL keyword.

For example:

>>> Publisher.objects.filter(name__         


        
相关标签:
1条回答
  • 2020-12-30 19:58

    You can use Q objects to do what you want, by bitwise OR-ing them together:

    from django.db.models import Q
    Publisher.objects.filter(Q(name__contains="press") | Q(country__contains="U.S.A"))
    
    0 讨论(0)
提交回复
热议问题