Repository: wagtail/wagtail

Issue:
FieldComparison.field_label should pick up labels from InlinePanel
For ParentalKey relations (which don't have a `verbose_name` property), FieldComparison creates a verbose_name from the field name:

https://github.com/wagtail/wagtail/blob/7ad79c9a4a7ec89a7d353db442268f24d08064c6/wagtail/admin/compare.py#L26-L28

This isn't ideal, particularly when `related_query_name` has been set on the relation - see https://github.com/wagtail/wagtail/pull/4579#issuecomment-412932533. It would be better to have InlinePanel pass its own label (if one is supplied) to FieldComparison as part of `InlinePanel.get_comparison`.


Discussion:
Is this still open? Can I work on it?
Go for it @sandilsranasinghe - please be sure to include unit tests with any PR and reach out if you need a hand. 
Just a couple of questions, is it okay to add a new default argument to ChildRelationComparison init method? Also should I add new unit tests to test_compare or test_edit_handlers if changing the `InlinePanel.get_comparison` method?
@sandilsranasinghe 
The default Arg should be ok - if it can be done in a way that won't break existing usage without it. 

Good call on adding those extra unit tests. 

Thanks

Resolving patch:
diff --git a/wagtail/admin/compare.py b/wagtail/admin/compare.py
--- a/wagtail/admin/compare.py
+++ b/wagtail/admin/compare.py
@@ -423,11 +423,12 @@ class ChildRelationComparison:
     is_field = False
     is_child_relation = True
 
-    def __init__(self, field, field_comparisons, obj_a, obj_b):
+    def __init__(self, field, field_comparisons, obj_a, obj_b, label=""):
         self.field = field
         self.field_comparisons = field_comparisons
         self.val_a = getattr(obj_a, field.related_name)
         self.val_b = getattr(obj_b, field.related_name)
+        self.label = label
 
     def field_label(self):
         """
@@ -437,7 +438,12 @@ def field_label(self):
 
         if verbose_name is None:
             # Relations don't have a verbose_name
-            verbose_name = self.field.name.replace("_", " ")
+            if self.label:
+                # If the panel has a label, we set it instead.
+                # See InlinePanel.get_comparision for usage
+                verbose_name = self.label
+            else:
+                verbose_name = self.field.name.replace("_", " ")
 
         return capfirst(verbose_name)
 
diff --git a/wagtail/admin/panels.py b/wagtail/admin/panels.py
--- a/wagtail/admin/panels.py
+++ b/wagtail/admin/panels.py
@@ -920,6 +920,7 @@ def get_comparison(self):
                     compare.ChildRelationComparison,
                     self.panel.db_field,
                     field_comparisons,
+                    label=self.label,
                 )
             ]
 


Test patch:
diff --git a/wagtail/admin/tests/test_compare.py b/wagtail/admin/tests/test_compare.py
--- a/wagtail/admin/tests/test_compare.py
+++ b/wagtail/admin/tests/test_compare.py
@@ -1265,6 +1265,30 @@ def test_hasnt_changed_with_different_id(self):
         self.assertEqual(added, [0])  # Add new Father Christmas
         self.assertEqual(deleted, [0])  # Delete old Father Christmas
 
+    def test_panel_label_as_field_label(self):
+        # Just to check whether passing `label` changes field_label
+        event_page = EventPage(title="Event page", slug="event")
+        event_page.speakers.add(
+            EventPageSpeaker(
+                first_name="Father",
+            )
+        )
+
+        comparison = self.comparison_class(
+            EventPage._meta.get_field("speaker"),
+            [
+                partial(
+                    self.field_comparison_class,
+                    EventPageSpeaker._meta.get_field("first_name"),
+                )
+            ],
+            event_page,
+            event_page,
+            label="Speakers",
+        )
+
+        self.assertEqual(comparison.field_label(), "Speakers")
+
 
 class TestChildObjectComparison(TestCase):
     field_comparison_class = compare.FieldComparison
diff --git a/wagtail/admin/tests/test_edit_handlers.py b/wagtail/admin/tests/test_edit_handlers.py
--- a/wagtail/admin/tests/test_edit_handlers.py
+++ b/wagtail/admin/tests/test_edit_handlers.py
@@ -1224,6 +1224,29 @@ def test_invalid_inlinepanel_declaration(self):
             )
 
 
+class TestInlinePanelGetComparison(TestCase):
+    fixtures = ["test.json"]
+
+    def setUp(self):
+        self.request = RequestFactory().get("/")
+        user = AnonymousUser()  # technically, Anonymous users cannot access the admin
+        self.request.user = user
+
+    def test_get_comparison(self):
+        # Test whether the InlinePanel passes it's label in get_comparison
+
+        page = Page.objects.get(id=4).specific
+        comparison = (
+            page.get_edit_handler()
+            .bind_to(instance=page, request=self.request)
+            .get_comparison()
+        )
+
+        comparison = [comp(page, page) for comp in comparison]
+        field_labels = [comp.field_label() for comp in comparison]
+        self.assertIn("Speakers", field_labels)
+
+
 class TestInlinePanelRelatedModelPanelConfigChecks(TestCase):
     def setUp(self):
         self.original_panels = EventPageSpeaker.panels