Pārlūkot izejas kodu

Add image and introduction fields to locations index

Scot Hacker 8 gadi atpakaļ
vecāks
revīzija
988fb54ba3

+ 22 - 0
bakerydemo/locations/migrations/0004_locationsindexpage_image.py

@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-17 08:20
+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'),
+        ('locations', '0003_auto_20170215_0723'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='locationsindexpage',
+            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'),
+        ),
+    ]

+ 20 - 0
bakerydemo/locations/migrations/0005_locationsindexpage_introduction.py

@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-17 08:24
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('locations', '0004_locationsindexpage_image'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='locationsindexpage',
+            name='introduction',
+            field=models.TextField(blank=True, help_text='Text to describe the index page'),
+        ),
+    ]

+ 16 - 0
bakerydemo/locations/models.py

@@ -67,8 +67,24 @@ class LocationsIndexPage(Page):
     Index page for locations
     """
 
+    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 = ['LocationPage']
 
+    content_panels = Page.content_panels + [
+        FieldPanel('introduction'),
+        ImageChooserPanel('image'),
+    ]
+
     def get_context(self, request):
         context = super(LocationsIndexPage, self).get_context(request)
         context['locations'] = LocationPage.objects.descendant_of(

+ 2 - 0
bakerydemo/templates/locations/locations_index_page.html

@@ -8,6 +8,8 @@
 {% endblock content-header %}
 
 {% block content-body %}
+    {{ page.introduction }}
+
     {% for location in locations %}
         <div>
             <a href="{% pageurl location %}">{{ location.title }}</a>