1
Query = 'com pu'
Query = Query.split()
busi = ""
for data in Query:
    busi += Business.objects.filter(Keywords__icontains=data)

When I use '+' symbol after busi variable for add all data according to filter that give error

Exception Type: TypeError

Exception Value:Can't convert 'QuerySet' object to str implicitly

How can I achieve that different Query part which split by that all give different-2 data and and both data in single busi object

2 Answers 2

2
from django.db.models import Q
Query = Query.split()
query = Q()
for data in Query:
    query |= Q(keyword_name__icontains=data)
Business= Business.objects.filter(query)
Sign up to request clarification or add additional context in comments.

Comments

0

Instead use &:

busi = None

q = Business.objects.filter(Keywords__icontains=data)

if busi is None:
    busi = q
else:
    busi = busi & q

2 Comments

Here what is data and what will you get in q ?What you want try? if busi is None: ?
q is the small chunk that you will get for each i (the way you were trying). It is just adding the querrysets. initially busi is naone as you have put empty string. The error you are getting is because of that as you cannot add an string to a queryset (busi).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.