瀏覽代碼

Add image and intro fields to breads page

Scot Hacker 8 年之前
父節點
當前提交
bc54cb4c65
共有 2 個文件被更改,包括 44 次插入2 次删除
  1. 27 0
      bakerydemo/breads/migrations/0002_auto_20170217_0853.py
  2. 17 2
      bakerydemo/breads/models.py

+ 27 - 0
bakerydemo/breads/migrations/0002_auto_20170217_0853.py

@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-17 08:53
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('wagtailimages', '0018_remove_rendition_filter'),
+        ('breads', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='breadsindexpage',
+            name='image',
+            field=models.ForeignKey(blank=True, help_text='Location listing image', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.Image'),
+        ),
+        migrations.AddField(
+            model_name='breadsindexpage',
+            name='introduction',
+            field=models.TextField(blank=True, help_text='Text to describe the index page'),
+        ),
+    ]

+ 17 - 2
bakerydemo/breads/models.py

@@ -11,7 +11,6 @@ from wagtail.wagtailsnippets.models import register_snippet
 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
 
 
-
 @register_snippet
 class Country(models.Model):
     """
@@ -103,8 +102,24 @@ class BreadsIndexPage(Page):
     BreadPage - so that it works as an index page
     """
 
+    introduction = models.TextField(
+        help_text='Text to describe the index page',
+        blank=True)
+    image = models.ForeignKey(
+        'wagtailimages.Image',
+        null=True,
+        blank=True,
+        on_delete=models.SET_NULL,
+        related_name='+',
+        help_text='Location listing image'
+    )
     subpage_types = ['BreadPage']
 
+    content_panels = Page.content_panels + [
+        FieldPanel('introduction'),
+        ImageChooserPanel('image'),
+    ]
+
     def get_context(self, request):
         context = super(BreadsIndexPage, self).get_context(request)
 
@@ -112,7 +127,7 @@ class BreadsIndexPage(Page):
         # replace this with your own query as appropriate
         all_resources = self.get_children().live()
 
-        paginator = Paginator(all_resources, 5) # Show 5 resources per page
+        paginator = Paginator(all_resources, 5)  # Show 5 resources per page
 
         page = request.GET.get('page')
         try: