From 983a29d84134425d5dd8c5487e9894375339845d Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Fri, 12 Jan 2018 15:31:07 +0000
Subject: [PATCH] Add icons and related pages to labs

---
 .../migrations/0003_icon_and_related_pages.py | 36 +++++++++++++++++++
 opentech/public/funds/models.py               | 15 ++++++--
 2 files changed, 49 insertions(+), 2 deletions(-)
 create mode 100644 opentech/public/funds/migrations/0003_icon_and_related_pages.py

diff --git a/opentech/public/funds/migrations/0003_icon_and_related_pages.py b/opentech/public/funds/migrations/0003_icon_and_related_pages.py
new file mode 100644
index 000000000..ba0f01802
--- /dev/null
+++ b/opentech/public/funds/migrations/0003_icon_and_related_pages.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.8 on 2018-01-12 15:19
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import modelcluster.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('images', '0001_initial'),
+        ('public_funds', '0002_labindex_labpage'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='labpage',
+            name='icon',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='images.CustomImage'),
+        ),
+        migrations.CreateModel(
+            name='LabPageRelatedPage',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('sort_order', models.IntegerField(blank=True, editable=False, null=True)),
+                ('page', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailcore.Page')),
+                ('source_page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='related_pages', to='public_funds.LabPage')),
+            ],
+            options={
+                'ordering': ['sort_order'],
+                'abstract': False,
+            },
+        ),
+    ]
diff --git a/opentech/public/funds/models.py b/opentech/public/funds/models.py
index bbb99dc06..8e01ca148 100644
--- a/opentech/public/funds/models.py
+++ b/opentech/public/funds/models.py
@@ -3,15 +3,21 @@ from django.core.exceptions import ValidationError
 from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
 from django.db import models
 
+from modelcluster.fields import ParentalKey
 from wagtail.wagtailadmin.edit_handlers import (
     FieldPanel,
+    InlinePanel,
     MultiFieldPanel,
     PageChooserPanel,
     StreamFieldPanel,
 )
 from wagtail.wagtailcore.fields import StreamField
+from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
 
-from opentech.public.utils.models import BasePage
+from opentech.public.utils.models import (
+    BasePage,
+    RelatedPage,
+)
 
 from .blocks import FundBlock
 
@@ -59,6 +65,10 @@ class FundIndex(BasePage):
         return context
 
 
+class LabPageRelatedPage(RelatedPage):
+    source_page = ParentalKey('LabPage', related_name='related_pages')
+
+
 class LabPage(BasePage):
     subpage_types = []
     parent_page_types = ['LabIndex']
@@ -83,7 +93,7 @@ class LabPage(BasePage):
     body = StreamField(FundBlock())
 
     content_panels = BasePage.content_panels + [
-        FieldPanel('icon'),
+        ImageChooserPanel('icon'),
         FieldPanel('introduction'),
         MultiFieldPanel([
             # Limit to lab pages once created
@@ -92,6 +102,7 @@ class LabPage(BasePage):
             FieldPanel('link_text'),
         ], heading='Link for lab application'),
         StreamFieldPanel('body'),
+        InlinePanel('related_pages', label="Related pages"),
     ]
 
     @property
-- 
GitLab