Browse Source

Use MultipleChooserPanel instead of InlinePanel in BlogPage and RecipePage

It allows selecting multiple authors at once and functions as a great
demo of this panel.
Storm B. Heg 1 year ago
parent
commit
137e8e6f08
2 changed files with 11 additions and 4 deletions
  1. 3 2
      bakerydemo/blog/models.py
  2. 8 2
      bakerydemo/recipes/models.py

+ 3 - 2
bakerydemo/blog/models.py

@@ -6,7 +6,7 @@ from django.shortcuts import redirect, render
 from modelcluster.contrib.taggit import ClusterTaggableManager
 from modelcluster.contrib.taggit import ClusterTaggableManager
 from modelcluster.fields import ParentalKey
 from modelcluster.fields import ParentalKey
 from taggit.models import Tag, TaggedItemBase
 from taggit.models import Tag, TaggedItemBase
-from wagtail.admin.panels import FieldPanel, InlinePanel
+from wagtail.admin.panels import FieldPanel, MultipleChooserPanel
 from wagtail.contrib.routable_page.models import RoutablePageMixin, route
 from wagtail.contrib.routable_page.models import RoutablePageMixin, route
 from wagtail.fields import StreamField
 from wagtail.fields import StreamField
 from wagtail.models import Orderable, Page
 from wagtail.models import Orderable, Page
@@ -76,8 +76,9 @@ class BlogPage(Page):
         FieldPanel("image"),
         FieldPanel("image"),
         FieldPanel("body"),
         FieldPanel("body"),
         FieldPanel("date_published"),
         FieldPanel("date_published"),
-        InlinePanel(
+        MultipleChooserPanel(
             "blog_person_relationship",
             "blog_person_relationship",
+            chooser_field_name="person",
             heading="Authors",
             heading="Authors",
             label="Author",
             label="Author",
             panels=None,
             panels=None,

+ 8 - 2
bakerydemo/recipes/models.py

@@ -1,6 +1,11 @@
 from django.db import models
 from django.db import models
 from modelcluster.fields import ParentalKey
 from modelcluster.fields import ParentalKey
-from wagtail.admin.panels import FieldPanel, HelpPanel, InlinePanel, MultiFieldPanel
+from wagtail.admin.panels import (
+    FieldPanel,
+    HelpPanel,
+    MultiFieldPanel,
+    MultipleChooserPanel,
+)
 from wagtail.fields import RichTextField, StreamField
 from wagtail.fields import RichTextField, StreamField
 from wagtail.models import Orderable, Page
 from wagtail.models import Orderable, Page
 from wagtail.search import index
 from wagtail.search import index
@@ -85,8 +90,9 @@ class RecipePage(Page):
             heading="Preface",
             heading="Preface",
         ),
         ),
         FieldPanel("body"),
         FieldPanel("body"),
-        InlinePanel(
+        MultipleChooserPanel(
             "recipe_person_relationship",
             "recipe_person_relationship",
+            chooser_field_name="person",
             heading="Authors",
             heading="Authors",
             label="Author",
             label="Author",
             help_text="Select between one and three authors",
             help_text="Select between one and three authors",