Created
February 28, 2019 22:02
-
-
Save KalobTaulien/22e3591b7e71e585fc48e5a6aa82c71c to your computer and use it in GitHub Desktop.
Getting BlogPostPages by their assigned authors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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