browse category filter
This commit is contained in:
parent
8ef158c034
commit
06e3172234
|
@ -16,9 +16,15 @@
|
|||
{% block main %}
|
||||
<div class="container-fluid">
|
||||
<div class="row mb-5">
|
||||
<div class="col col-xxl mb-5">
|
||||
{# TODO: center in mobile view #}
|
||||
<div class="col col-xxl mb-5" id="headline">
|
||||
<h1 class="display-1">Browse</h1>
|
||||
{# center headline on small screens #}
|
||||
<script>
|
||||
if (screen.width < 480) {
|
||||
col = document.getElementById("headline")
|
||||
col.classList.add("text-center")
|
||||
};
|
||||
</script>
|
||||
</div>
|
||||
<div class="col-sm-3">
|
||||
<div class="container-fluid w-100 h-100 p-2">
|
||||
|
|
|
@ -8,6 +8,7 @@ from start.views import SearchableView
|
|||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Index(TemplateView, SearchableView):
|
||||
"""
|
||||
The index page of the gawa/blog app.
|
||||
|
@ -20,15 +21,17 @@ class Index(TemplateView, SearchableView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['featured_posts'] = BlogPost.objects.filter(featured=True, public=True)
|
||||
context['featured_posts'] = BlogPost.objects.filter(
|
||||
featured=True, public=True)
|
||||
return context
|
||||
|
||||
|
||||
class Post(DetailView):
|
||||
"""
|
||||
Main page of a blog post
|
||||
"""
|
||||
|
||||
model=BlogPost
|
||||
model = BlogPost
|
||||
template_name = "blog/blogpost.html"
|
||||
context_object_name = "post"
|
||||
|
||||
|
@ -37,6 +40,7 @@ class Post(DetailView):
|
|||
context['featured_posts'] = BlogPost.objects.filter(featured=True)
|
||||
return context
|
||||
|
||||
|
||||
class Browse(ListView):
|
||||
"""
|
||||
Scroll through a list of blog posts
|
||||
|
@ -45,10 +49,19 @@ class Browse(ListView):
|
|||
Of course, Articles will also show up in the MainSearchView
|
||||
"""
|
||||
|
||||
model=BlogPost
|
||||
model = BlogPost
|
||||
template_name = "blog/browse.html"
|
||||
context_object_name = "posts"
|
||||
|
||||
def get_queryset(self):
|
||||
objects = BlogPost.objects.all()
|
||||
if "category" in self.request.GET and len(
|
||||
self.request.GET["category"].strip()) > 0:
|
||||
category = self.request.GET["category"]
|
||||
category = Category.objects.get(slug=category)
|
||||
objects = objects.filter(category=category)
|
||||
return objects
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['featured_posts'] = BlogPost.objects.filter(featured=True)
|
||||
|
|
Loading…
Reference in New Issue