22 lines
629 B
Python
22 lines
629 B
Python
import os
|
|
os.environ['DJANGO_SETTINGS_MODULE']='web.settings'
|
|
from web.library.models import *
|
|
from django.db.models import Q
|
|
|
|
def search(string):
|
|
words = string.split()
|
|
basic_query = Book.objects
|
|
for word in words:
|
|
basic_query=basic_query.filter(Q(title__icontains=word) |
|
|
Q(subtitle__icontains=word) |
|
|
Q(id__id__icontains=word) |
|
|
Q(person__person__first_name__icontains=word) |
|
|
Q(person__person__last_name__icontains=word))
|
|
return remove_duplicates(basic_query.all())
|
|
|
|
def remove_duplicates(list):
|
|
d = {}
|
|
for i in list:
|
|
d[i]=None
|
|
return d.keys()
|