mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Started on search functions
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user