Quellcode durchsuchen

Basic template for blogs

Edd Baldry vor 8 Jahren
Ursprung
Commit
4529b2789b

+ 14 - 4
bakerydemo/blog/models.py

@@ -72,12 +72,16 @@ class BlogPage(Page):
         FieldPanel('tags'),
     ]
 
-    def people(self):
-        people = [
-             n.people for n in self.person_blog_relationship.all()
+    def authors(self):
+        authors = [
+             n.people for n in self.blog_person_relationship.all()
         ]
 
-        return people
+        return authors
+
+    # def tags(self):
+    #     tags = self.tags.all()
+    #     return tags
 
     parent_page_types = [
        'BlogIndexPage'
@@ -123,4 +127,10 @@ class BlogIndexPage(Page):
         'BlogPage'
     ]
 
+    def get_context(self, request):
+        context = super(BlogIndexPage, self).get_context(request)
+        context['posts'] = BlogPage.objects.descendant_of(
+            self).live().order_by(
+            '-first_published_at')
+        return context
     # api_fields = ['introduction']

+ 10 - 0
bakerydemo/templates/blog/blog_index_page.html

@@ -0,0 +1,10 @@
+{% extends "base.html" %}
+{% load wagtailimages_tags %}
+
+{% block content %}
+    {{ page.title }}
+
+    {% for post in posts %}
+        <div><a href="{{ post.slug }}">{{ post.title }}</a></div>
+    {% endfor %}
+{% endblock content %}

+ 21 - 0
bakerydemo/templates/blog/blog_page.html

@@ -0,0 +1,21 @@
+{% extends "base.html" %}
+{% load wagtailimages_tags %}
+
+{% block content %}
+    <h1>{{ page.title }}</h1>
+    <figure>
+      {% image self.image fill-600x600 %}
+    </figure>
+
+    {% for tag in page.tags.all  %}
+        {{ tag }}
+    {% endfor %}
+
+    <date>{{ page.date_published }}</date>
+    
+    {% for author in page.authors %}
+        <li>{{ author }}</li>
+    {% endfor %}
+
+    {{ page.body }}
+{% endblock content %}