I have a parameter search_query and I want to get all the objects that consist search_query using only raw sql(I know that Django has built-in functions for that) Here is my code:
def search(request):
cursor = connection.cursor()
cursor.execute("SELECT (Lastname + ' ' + Firstname + ' ' + Patronymic) as n from Person")
data = dictfetchall(cursor)
search_query = request.GET.get('search','')
cursor.execute("SELECT (Lastname + ' ' + Firstname + ' ' + Patronymic) as n from Person WHERE Lastname LIKE %s",[search_query])
data = dictfetchall(cursor)
return render(request,'other.html',{'data':data,'search_q':search_query})
Tried to do like this WHERE Lastname LIKE %%s%
, but it didn't work. Couldn't find anything in the internet((