Update Django, add search.
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 18 Aug 2020 14:04:34 +0000 (16:04 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 18 Aug 2020 14:04:34 +0000 (16:04 +0200)
requirements.txt
src/archive/templates/archive/audiobook_list.html
src/archive/views.py
src/audiobooks/settings.py

index c355845..bfe2ad6 100644 (file)
@@ -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
index f4a49a9..b006726 100644 (file)
 
 
 {% block file-list-info %}
+  <form>
+    <div class="input-group">
+      <input class="form-control" name="s" value="{{ request.GET.s }}">
+      <div class="input-group-append">
+       <button class="btn btn-primary">Szukaj</button>
+      </div>
+    </div>
+  </form>
 {% endblock %}
 
 {% block file-list-wrapper %}
index 2170aff..fab7a1c 100644 (file)
@@ -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')
index 901da0f..f36fe81 100644 (file)
@@ -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',