瀏覽代碼

Relationships between locations and about page, blogs and authors

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

+ 31 - 0
bakerydemo/base/migrations/0004_aboutlocationrelationship.py

@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-09 17:06
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import modelcluster.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('locations', '0002_auto_20170209_1651'),
+        ('base', '0003_auto_20170209_1651'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='AboutLocationRelationship',
+            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)),
+                ('locations', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='about_location_relationship', to='locations.LocationPage')),
+                ('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='location_about_relationship', to='base.AboutPage')),
+            ],
+            options={
+                'ordering': ['sort_order'],
+                'abstract': False,
+            },
+        ),
+    ]

+ 23 - 22
bakerydemo/base/models.py

@@ -13,7 +13,8 @@ from wagtail.wagtailadmin.edit_handlers import (
         InlinePanel,
         FieldRowPanel,
         StreamFieldPanel,
-        MultiFieldPanel
+        MultiFieldPanel,
+        PageChooserPanel
         )
 from wagtail.wagtailsnippets.models import register_snippet
 from wagtail.wagtailsnippets.edit_handlers import SnippetChooserPanel
@@ -50,21 +51,21 @@ class People(ClusterableModel):
         verbose_name_plural = 'People'
 
 
-# class AboutLocationRelationship(Orderable, models.Model):
-#     """
-#     This defines the relationship between the `LocationPage` within the `locations`
-#     app and the About page below allowing us to add locations to the about
-#     section.
-#     """
-#     about = ParentalKey(
-#         'About', related_name='location_about_relationship'
-#     )
-#     locations = models.ForeignKey(
-#         'locations.LocationPage', related_name='about_location_relationship'
-#     )
-#     panels = [
-#         PageChooserPanel('locations')
-#     ]
+class AboutLocationRelationship(Orderable, models.Model):
+    """
+    This defines the relationship between the `LocationPage` within the `locations`
+    app and the About page below allowing us to add locations to the about
+    section.
+    """
+    page = ParentalKey(
+        'AboutPage', related_name='location_about_relationship'
+    )
+    locations = models.ForeignKey(
+        'locations.LocationPage', related_name='about_location_relationship'
+    )
+    panels = [
+        PageChooserPanel('locations')
+    ]
 
 
 class AboutPage(Page):
@@ -91,11 +92,11 @@ class AboutPage(Page):
     content_panels = Page.content_panels + [
         ImageChooserPanel('image'),
         StreamFieldPanel('body'),
-        #    InlinePanel(
-        #        'about_location_relationship',
-        #        label='Locations',
-        #        min_num=None
-        #        ),
+        InlinePanel(
+           'location_about_relationship',
+           label='Locations',
+           min_num=None
+           ),
     ]
 
     # parent_page_types = [
@@ -120,7 +121,7 @@ def getImageCollections():
             )]
         return collection_images
     except:
-        return [('','')]
+        return [('', '')]
 
 
 class GalleryPage(Page):

+ 19 - 0
bakerydemo/breads/migrations/0002_auto_20170209_1713.py

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-09 17:13
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('breads', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.RenameModel(
+            old_name='BreadsLandingPage',
+            new_name='BreadsIndexPage',
+        ),
+    ]

+ 6 - 2
bakerydemo/breads/models.py

@@ -28,13 +28,13 @@ class Country(models.Model):
         verbose_name_plural = "Countries of Origin"
 
 
-class BreadsLandingPage(Page):
+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.
     '''
 
-    pass
+    subpage_types = ['BreadPage']
 
 
 @register_snippet
@@ -99,3 +99,7 @@ class BreadPage(Page):
         index.SearchField('title'),
         index.SearchField('description'),
     ]
+
+    parent_page_types = [
+       'BreadsIndexPage'
+    ]

+ 19 - 0
bakerydemo/locations/migrations/0003_auto_20170209_1711.py

@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.5 on 2017-02-09 17:11
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('locations', '0002_auto_20170209_1651'),
+    ]
+
+    operations = [
+        migrations.RenameModel(
+            old_name='LocationsLandingPage',
+            new_name='LocationsIndexPage',
+        ),
+    ]

+ 6 - 2
bakerydemo/locations/models.py

@@ -61,12 +61,12 @@ class LocationOperatingHours(Orderable, OperatingHours):
     )
 
 
-class LocationsLandingPage(Page):
+class LocationsIndexPage(Page):
     '''
     Home page for locations
     '''
 
-    pass
+    subpage_types = ['LocationPage']
 
 
 class LocationPage(Page):
@@ -107,3 +107,7 @@ class LocationPage(Page):
 
     def __str__(self):
         return self.name
+
+    parent_page_types = [
+       'LocationsIndexPage'
+    ]