瀏覽代碼

Basic template for breads app within context in index page

Edd Baldry 8 年之前
父節點
當前提交
b664bc6e35

+ 17 - 11
bakerydemo/breads/models.py

@@ -1,7 +1,5 @@
-
 from django.db import models
 
-
 from wagtail.wagtailcore.models import Page
 from wagtail.wagtailcore.fields import StreamField
 from wagtail.wagtailadmin.edit_handlers import FieldPanel, StreamFieldPanel
@@ -28,15 +26,6 @@ class Country(models.Model):
         verbose_name_plural = "Countries of Origin"
 
 
-class BreadsIndexPage(Page):
-    '''
-    Home page for breads. Nothing needed in the model here - we'll just
-    create an instance, then pull its children into the template.
-    '''
-
-    subpage_types = ['BreadPage']
-
-
 @register_snippet
 class BreadType(models.Model):
     '''
@@ -103,3 +92,20 @@ class BreadPage(Page):
     parent_page_types = [
        'BreadsIndexPage'
     ]
+
+
+class BreadsIndexPage(Page):
+    '''
+    Index page for breads. We don't have any fields within our model but we need
+    to alter the page models context to return the child page objects - the
+    BreadPage - so that it works as an index page
+    '''
+
+    subpage_types = ['BreadPage']
+
+    def get_context(self, request):
+        context = super(BreadsIndexPage, self).get_context(request)
+        context['breads'] = BreadPage.objects.descendant_of(
+            self).live().order_by(
+            '-first_published_at')
+        return context

+ 1 - 16
bakerydemo/templates/base.html

@@ -1,4 +1,4 @@
-{% load compress static wagtailuserbar %}
+{% load static wagtailuserbar %}
 
 <!DOCTYPE html>
 <!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
@@ -11,14 +11,6 @@
         <title>{% block title %}{% if self.seo_title %}{{ self.seo_title }}{% else %}{{ self.title }}{% endif %}{% endblock %}{% block title_suffix %}{% endblock %}</title>
         <meta name="description" content="">
         <meta name="viewport" content="width=device-width, initial-scale=1">
-
-        {% compress css %}
-            <link rel="stylesheet" type="text/x-scss" href="{% static 'css/main.scss' %}">
-        {% endcompress %}
-
-        {% block extra_css %}
-
-        {% endblock %}
     </head>
 
     <body class="{% block body_class %}{% endblock %}">
@@ -26,13 +18,6 @@
 
         {% block content %}{% endblock %}
 
-        {% compress js %}
-            <script type="text/javascript" src="{% static 'js/main.js' %}"></script>
-        {% endcompress %}
-
-        {% block extra_js %}
-
-        {% endblock %}
     </body>
 </html>
 

+ 12 - 0
bakerydemo/templates/breads/bread_page.html

@@ -0,0 +1,12 @@
+{% extends "base.html" %}
+{% load wagtailimages_tags %}
+
+{% block content %}
+    <h1>{{ page.title }}</h1>
+    <figure>
+      {% image self.image fill-600x600 %}
+    </figure>
+    <p>{{ page.origin }}</p>
+    <p>{{ page.bread_type }}</p>
+    {{ page.description }}
+{% endblock content %}

+ 10 - 0
bakerydemo/templates/breads/breads_index_page.html

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