add search
This commit is contained in:
parent
06e3172234
commit
559eb3f9fa
|
@ -17,7 +17,11 @@
|
|||
<div class="container-fluid">
|
||||
<div class="row mb-5">
|
||||
<div class="col col-xxl mb-5" id="headline">
|
||||
<h1 class="display-1">Browse</h1>
|
||||
<a class="text-reset link-offset-2 link-underline link-underline-opacity-0"
|
||||
href="{% url "blog:browse" %}"
|
||||
style="display: inline-block;">
|
||||
<h1 class="display-1 w-0">Browse</h1>
|
||||
</a>
|
||||
{# center headline on small screens #}
|
||||
<script>
|
||||
if (screen.width < 480) {
|
||||
|
@ -63,6 +67,8 @@
|
|||
<div class="row mb-5">
|
||||
<div class="container-fluid p-0 w-100 h-100">
|
||||
<div class="row gap-3">
|
||||
{# TODO: display some info if the queryset is empty #}
|
||||
{# TODO: pagination #}
|
||||
{% for post in posts %}
|
||||
<div class="card col mx-auto my-2" style="min-width: 200px;">
|
||||
<a class="text-reset link-offset-2 link-underline link-underline-opacity-0"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from django.shortcuts import Http404, HttpResponse, get_object_or_404, render
|
||||
from django.utils.translation import get_language
|
||||
from django.views.generic import TemplateView, DetailView, ListView, View
|
||||
from django.db.models import Q
|
||||
from .models import BlogPost, Category
|
||||
|
||||
from start.views import SearchableView
|
||||
|
@ -58,8 +59,27 @@ class Browse(ListView):
|
|||
if "category" in self.request.GET and len(
|
||||
self.request.GET["category"].strip()) > 0:
|
||||
category = self.request.GET["category"]
|
||||
try:
|
||||
category = Category.objects.get(slug=category)
|
||||
objects = objects.filter(category=category)
|
||||
except Category.DoesNotExist:
|
||||
objects = objects.none()
|
||||
if "search" in self.request.GET and len(
|
||||
self.request.GET["search"].strip()) > 0:
|
||||
search = self.request.GET["search"]
|
||||
# __icontains matches those attributes that contain the
|
||||
# search string without caring about lower/upper cases
|
||||
objects = objects.filter(
|
||||
Q(title_en__icontains=search) |
|
||||
Q(title_de__icontains=search) |
|
||||
Q(subtitle_en__icontains=search) |
|
||||
Q(subtitle_de__icontains=search) |
|
||||
Q(desc_en__icontains=search) |
|
||||
Q(desc_de__icontains=search) |
|
||||
# Q(body_en__icontains=search) |
|
||||
# Q(body_de__icontains=search) |
|
||||
Q(slug__icontains=search)
|
||||
)
|
||||
return objects
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue