From: Radek Czajka Date: Tue, 18 Aug 2020 14:04:34 +0000 (+0200) Subject: Update Django, add search. X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/52421a3d925957f14d3fa2d8ce37ee82a4918e5e?hp=5ee0595f97148a89736d208b08021705d88784e2 Update Django, add search. --- diff --git a/requirements.txt b/requirements.txt index c355845..bfe2ad6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -i https://py.mdrn.pl:8443/simple -Django==3.0.6 +Django==3.1 django-cas-ng==4.1.1 django-bootstrap4==1.1.1 django-pglocks==1.0.4 diff --git a/src/archive/templates/archive/audiobook_list.html b/src/archive/templates/archive/audiobook_list.html index f4a49a9..b006726 100644 --- a/src/archive/templates/archive/audiobook_list.html +++ b/src/archive/templates/archive/audiobook_list.html @@ -13,6 +13,14 @@ {% block file-list-info %} +
+
+ +
+ +
+
+
{% endblock %} {% block file-list-wrapper %} diff --git a/src/archive/views.py b/src/archive/views.py index 2170aff..fab7a1c 100644 --- a/src/archive/views.py +++ b/src/archive/views.py @@ -5,6 +5,7 @@ from urllib.parse import quote from archive import settings from django.contrib.auth.decorators import permission_required +from django.contrib.postgres.search import SearchVector from django.urls import reverse from django.db.models import Q, Max from django.http import Http404, HttpResponse @@ -229,7 +230,11 @@ def list_publishing(request): class AudiobookList(ListView): - queryset = models.Audiobook.objects.all() + def get_queryset(self): + qs = models.Audiobook.objects.all() + if 's' in self.request.GET: + qs = qs.annotate(s=SearchVector('title', 'slug')).filter(s=self.request.GET['s']) + return qs @permission_required('archive.change_audiobook') diff --git a/src/audiobooks/settings.py b/src/audiobooks/settings.py index 901da0f..f36fe81 100644 --- a/src/audiobooks/settings.py +++ b/src/audiobooks/settings.py @@ -125,6 +125,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', + 'django.contrib.postgres', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'bootstrap4',