Skip to content

Instantly share code, notes, and snippets.

@KalobTaulien
Created February 28, 2019 22:02
Show Gist options
  • Save KalobTaulien/22e3591b7e71e585fc48e5a6aa82c71c to your computer and use it in GitHub Desktop.
Save KalobTaulien/22e3591b7e71e585fc48e5a6aa82c71c to your computer and use it in GitHub Desktop.
Getting BlogPostPages by their assigned authors
{% extends 'base.html' %}
{% block content %}
{% for post in posts %}
{{ post.title }}
{% endfor %}
{% endblock %}
class StaffPage(RoutablePageMixin, Page):
# fields here
# ...
# routable page for /staff/{author_slug}/
@route(r'^(?P<author_slug>[-\w]*)/$', name='author_page')
def author_page(self, request, author_slug):
context = self.get_context(request)
posts = BlogPostPage.objects.filter(blog_authors__in=[author_slug])
context['posts'] = posts
return render(request, 'staff/author_page.html', context)
get_context(self, request, *args, **kwargs):
context = super().get_context(request, *args, **kwargs)
context['all_authors'] = BlogAuthor.objects.all()
return context
{% extends 'base.html' %}
{% block content %}
{% for author in authors %}
{{ author.name }}
{% endfor %}
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment