Filter list search results to hide already added books

This commit is contained in:
Mouse Reeve
2021-04-26 08:02:30 -07:00
parent 0cb80aeb55
commit 0f6b5cc6be
3 changed files with 19 additions and 12 deletions

View File

@ -137,7 +137,11 @@ class List(View):
if query and request.user.is_authenticated:
# search for books
suggestions = connector_manager.local_search(query, raw=True)
suggestions = connector_manager.local_search(
query,
raw=True,
filters=[~Q(parent_work__editions__in=book_list.books.all())],
)
elif request.user.is_authenticated:
# just suggest whatever books are nearby
suggestions = request.user.shelfbook_set.filter(
@ -265,7 +269,7 @@ def add_book(request):
# if the book is already on the list, don't flip out
pass
path = reverse('list', args=[book_list.id])
path = reverse("list", args=[book_list.id])
return redirect("{:s}?{:s}".format(path, urlencode(request.GET)))