Nameless
Nameless

Reputation: 523

Get null or empty query set in django

    def get_queryset(self):
        key = self.request.GET['search_text']
        customer_list = customer_info.objects.all()
        # temp =
        for term in key.split():
            temp = temp | customer_list.filter(Q(fName__icontains=term)|Q(lName__icontains=term))
        return temp

How can I assign the value of temp to null query set of customer_info objects so that I could union temp with the filter list then return it. Basically, I am splitting the search box text and then filtering the table with each string in the list and combining the result initial result.

Upvotes: 1

Views: 871

Answers (1)

Alasdair
Alasdair

Reputation: 309099

You can get an empty queryset with none():

MyModel.objects.none()

An alternative approach is to or the Q() objects together instead of querysets:

q = Q()
for term in key.split():
    q = q | Q(fName__icontains=term) | Q(lName__icontains=term)
return customer_info.objects.filter(q)

Upvotes: 2

Related Questions