Started on search functions

This commit is contained in:
Mike Young
2019-12-04 23:08:20 -05:00
parent 759585a3b5
commit ed928e4237
3 changed files with 20 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ urlpatterns = [
path("download/<pk>", views.download, name="download"),
path("prev_page/<bookset>", views.prev_page, name="prev_page"),
path("next_page/<bookset>", views.next_page, name="next_page"),
path("search/<query>", views.search, name="search"),
]
if settings.DEBUG:
import debug_toolbar

View File

@@ -1,3 +1,4 @@
from django.contrib.postgres.search import SearchVector
from django.db import models
# Create your models here.
@@ -32,3 +33,9 @@ class Books(models.Model):
def get_absolute_url(self):
"""Returns the url to access a particular instance of MyModelName."""
return reverse("model-detail-view", args=[str(self.id)])
def generic_search(self, query):
results = Books.objects.annotate(
search=SearchVector("author", "title", "file_name")
).filter(str(query))
return results

View File

@@ -41,6 +41,18 @@ def prev_page(request, bookset):
)
def search(request, query=None):
breakpoint()
if query == None:
return False
else:
try:
_r = Books().generic_search(query)
return _r
except Exception as e:
return e
def book_set(_limit=None, _set=1):
if _limit is None:
_limit = 20 # TODO default from user choice