OR operator in Django model queries

前端 未结 2 629
孤街浪徒
孤街浪徒 2020-12-15 15:29

I\'m trying to use an OR operator in the Django filter() function. Right now I have

contactlist = Contact.objects.filter(last_name_         


        
2条回答
  •  囚心锁ツ
    2020-12-15 15:55

    Q objects

    from django.db.models import Q
    
    Contact.objects.filter(Q(last_name__icontains=request.POST['query']) | 
                                   Q(first_name__icontains=request.POST['query']))
    

提交回复
热议问题