Repository: netbox-community/netbox
Pull request: Adds site column to power feeds
<!--
    Thank you for your interest in contributing to NetBox! Please note that
    our contribution policy requires that a feature request or bug report be
    approved and assigned prior to opening a pull request. This helps avoid
    waste time and effort on a proposed change that we might not be able to
    accept.

    IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED
    TO YOU, IT WILL BE CLOSED AUTOMATICALLY.

    Please specify your assigned issue number on the line below.
-->
### Fixes: #13743

<!--
    Please include a summary of the proposed changes below.
-->


Problem statement:
Add "site" column to power feed list
### NetBox version

v3.6.1

### Feature type

Change to existing functionality

### Proposed functionality

I propose adding "Site" as a selectable column for the power feed view. The power feed model doesn't directly have a "Site" field, so the "Site" column would be populated from the associated Rack.

### Use case

When looking at a list of power feeds, it's helpful to, at a glance, know what site the power feed belongs to. This is especially useful if you have duplicate rack names across sites.

### Database changes

None.

### External dependencies

None.

Hints from issue discussion:
I just realized I can acheive this with a Custom Link, so that's a workaround for now.

If anyone else needs this, just import the following Custom Link using this YAML in the bulk importer:

```yaml
---
name: Site
content_types: dcim.powerfeed
weight: 1000
button_class: ghost-dark
link_text: '{{ object.rack.site.name }}'
link_url: '{{ object.rack.site.url }}'
enabled: true
```

Once the Custom Link is created, it can then be used as a field in the table view (which is essentialy what the FR here is asking for.)

The downside to this is that you'll get an extra link on the power feed view to the site, but... I guess that might be considered useful?

Anyway, I still think it should be in Netbox from the start but given it's easy enough to customize Netbox and get the same result this probably doesn't need to be prioritized.

Commit message: adds site column to power feeds #13743

Patch to review:
diff --git a/netbox/dcim/tables/power.py b/netbox/dcim/tables/power.py
index e4735bd5797..04aa9a2d6de 100644
--- a/netbox/dcim/tables/power.py
+++ b/netbox/dcim/tables/power.py
@@ -87,6 +87,10 @@ class PowerFeedTable(TenancyColumnsMixin, CableTerminationTable):
         linkify=True,
         verbose_name=_('Tenant')
     )
+    site = tables.TemplateColumn(
+        template_code='''{% if record.rack %}{{ record.rack.site|linkify }}{% else %}&mdash;{% endif %}''',
+        verbose_name=_('Site'),
+    )
     comments = columns.MarkdownColumn(
         verbose_name=_('Comments'),
     )
@@ -97,9 +101,9 @@ class PowerFeedTable(TenancyColumnsMixin, CableTerminationTable):
     class Meta(NetBoxTable.Meta):
         model = PowerFeed
         fields = (
-            'pk', 'id', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase',
-            'max_utilization', 'mark_connected', 'cable', 'cable_color', 'link_peer', 'available_power', 'tenant',
-            'tenant_group', 'description', 'comments', 'tags', 'created', 'last_updated',
+            'pk', 'id', 'name', 'power_panel', 'site', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage',
+            'phase', 'max_utilization', 'mark_connected', 'cable', 'cable_color', 'link_peer', 'available_power',
+            'tenant', 'tenant_group', 'description', 'comments', 'tags', 'created', 'last_updated',
         )
         default_columns = (
             'pk', 'name', 'power_panel', 'rack', 'status', 'type', 'supply', 'voltage', 'amperage', 'phase', 'cable',


Code review comments:
diff_hunk: @@ -87,6 +87,10 @@ class PowerFeedTable(TenancyColumnsMixin, CableTerminationTable):
         linkify=True,
         verbose_name=_('Tenant')
     )
+    site = tables.TemplateColumn(
path: netbox/dcim/tables/power.py
text: @user1:
We should be able to do this with a regular column by setting its accessor to `rack__site` and `linkify=True`.