Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0
This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
worblehat-old/python/search.py

35 lines
1.3 KiB
Python

import os
os.environ['DJANGO_SETTINGS_MODULE']='web.settings'
from web.library.models import *
from django.db.models import Q
from util import *
def search_person(search_strings, search_description=False):
basic_query=Person.objects.select_related('books__book__alt_titles')
for word in search_strings:
basic_query=basic_query.filter(Q(first_name__icontains=word) |
Q(last_name__icontains=word) |
Q(id__icontains=word) |
Q(books__book__isbn__icontains=word) |
Q(books__book__title__icontains=word) |
Q(books__book__alt_titles__alt_title=word) |
Q(books__book__id__id__icontains=word))
return remove_duplicates(basic_query.all())
def search_book(search_strings, search_description=False):
basic_query = Book.objects.select_related('persons__person','id','alt_titles')
for word in search_strings:
basic_query=basic_query.filter(Q(title__icontains=word) |
Q(subtitle__icontains=word) |
Q(alt_titles__alt_title__icontains=word) |
Q(id__id__icontains=word) |
Q(persons__person__first_name__icontains=word) |
Q(persons__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()