Repository: nautobot/nautobot

Issue:
Job Results Page - Use Meta Name Attribute
<!--
    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.

    This form is only for proposing specific new features or enhancements.
    If you have a general idea or question, please start a discussion instead:
    https://github.com/nautobot/nautobot/discussions

    Please describe the environment in which you are running Nautobot.
-->
### Environment
* Python version: 3.6.13
* Nautobot version: 1.0.1

<!--
    Describe in detail the new functionality you are proposing. Include any
    specific changes to work flows, data models, or the user interface.
-->
### Proposed Functionality

When displaying Job Results we should display the attribute in the Meta as the name of the Job result. The current job display is: `<folder path>/file/class_name`


<!--
    Convey an example use case for your proposed feature. Write from the
    perspective of a Nautobot user who would benefit from the proposed
    functionality and describe how.
--->
### Use Case

Allow for friendly names
Allow for customized names (such as many branch sites to filter on the one item)
<!--
    Note any changes to the database schema necessary to support the new
    feature. For example, does the proposal require adding a new model or
    field? (Not all new features require database changes.)
--->
### Database Changes

None

<!--
    List any new dependencies on external libraries or services that this new
    feature would introduce. For example, does the proposal require the
    installation of a new Python package? (Not all new features introduce new
    dependencies.)
-->
### External Dependencies

None


Discussion:
This could also be a configurable option for those that prefer the directory path as the name.  However, I personally agree having a user friendly name is definitely needed.


Resolving patch:
diff --git a/nautobot/extras/models/models.py b/nautobot/extras/models/models.py
--- a/nautobot/extras/models/models.py
+++ b/nautobot/extras/models/models.py
@@ -826,6 +826,18 @@ def related_object(self):
 
         return None
 
+    @property
+    def related_name(self):
+        """
+        Similar to self.name, but if there's an appropriate `related_object`, use its name instead.
+        """
+        related_object = self.related_object
+        if not related_object:
+            return self.name
+        if hasattr(related_object, "name"):
+            return related_object.name
+        return str(related_object)
+
     def get_absolute_url(self):
         return reverse("extras:jobresult", kwargs={"pk": self.pk})
 
diff --git a/nautobot/extras/tables.py b/nautobot/extras/tables.py
--- a/nautobot/extras/tables.py
+++ b/nautobot/extras/tables.py
@@ -259,8 +259,8 @@ def job_creator_link(value, record):
 class JobResultTable(BaseTable):
     pk = ToggleColumn()
     obj_type = tables.Column(verbose_name="Object Type", accessor="obj_type.name")
-    name = tables.Column(linkify=job_creator_link)
-    job_id = tables.Column(linkify=job_creator_link, verbose_name="Job ID")
+    related_object = tables.Column(verbose_name="Related Object", linkify=job_creator_link, accessor="related_name")
+    name = tables.Column()
     created = tables.DateTimeColumn(linkify=True, format=settings.SHORT_DATETIME_FORMAT)
     status = tables.TemplateColumn(
         template_code="{% include 'extras/inc/job_label.html' with result=record %}",
@@ -282,16 +282,16 @@ class Meta(BaseTable.Meta):
         fields = (
             "pk",
             "created",
-            "obj_type",
             "name",
-            "job_id",
+            "obj_type",
+            "related_object",
             "duration",
             "completed",
             "user",
             "status",
             "data",
         )
-        default_columns = ("pk", "created", "name", "user", "status", "data")
+        default_columns = ("pk", "created", "related_object", "user", "status", "data")
 
 
 class ObjectChangeTable(BaseTable):


Test patch: