OR operator in Django model queries

前端 未结 2 630
孤街浪徒
孤街浪徒 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']))
    
    0 讨论(0)
  • 2020-12-15 16:16
    result = Contact.objects.filter(last_name__icontains=request.POST['query']) | Contact.objects.filter(first_name__icontains=request.POST['query'])
    
    0 讨论(0)
提交回复
热议问题