Repository: netbox-community/netbox
Pull request: Fixes #10580
<!--
    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 filing a pull request. This helps avoid
    wasting time and effort on something that we might not be able to accept.

    IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED
    TO YOU, IT WE BE CLOSED AUTOMATICALLY.

    Specify your assigned issue number on the line below.
-->
### Fixes: #10580 

<!--
    Please include a summary of the proposed changes below.
-->
Changes accessor in IPAddressTable for the assigned column to switch it from linking to the IP address page to the linked interface's page.

Problem statement:
link 'assigned' checkbox to device rather than ip
### NetBox version

v3.3.5

### Feature type

Change to existing functionality

### Proposed functionality

When searching for an IP, the result shows the 'assigned' green checkbox if an IP address is assigned to a device/vm/...
The current link of the green check is to the IP address object.
I like to propose to change that to the device/vm/... the IP is assigned to.

### Use case

When the checkbox is clicked, it is more intuitive to go to the device it is assigned to.
Now it requires 2 additional clicks to go to the device.


### Database changes

_No response_

### External dependencies

_No response_

Hints from issue discussion:
@jeremystretch I can work on implementing this
Got around to digging into the code and familiarizing myself with this portion. I see that there are already two columns (that are just hidden by default) that show both A. the device, and B. the interface. 

I do agree that clicking the checkmark to go to the device would be more intuitive, however is it more intuitive to send the user to the device, or the interface? Or perhaps, a third solution: if the IP is listed as the primary IP of a device, send them to a device, otherwise send them to the interface? Thoughts?
The checkbox is very slim. The device or interface table makes the table wider.
To be honest, the interface view has less added value than then device view. I don't see a reason to link it to the interface.

Maybe we can link it to the interface tab of the device?
IMO linking to the interface is preferable, but I don't have a strong opinion.

Commit message: set IP assigned check to link to interface

Patch to review:
diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py
index a820385ed83..3be6978b4cb 100644
--- a/netbox/ipam/tables/ip.py
+++ b/netbox/ipam/tables/ip.py
@@ -374,7 +374,7 @@ class IPAddressTable(TenancyColumnsMixin, NetBoxTable):
         verbose_name='NAT (Outside)'
     )
     assigned = columns.BooleanColumn(
-        accessor='assigned_object_id',
+        accessor='assigned_object',
         linkify=True,
         verbose_name='Assigned'
     )


Code review comments:
diff_hunk: @@ -374,7 +374,7 @@ class IPAddressTable(TenancyColumnsMixin, NetBoxTable):
         verbose_name='NAT (Outside)'
     )
     assigned = columns.BooleanColumn(
-        accessor='assigned_object_id',
+        accessor='assigned_object',
         linkify=True,
path: netbox/ipam/tables/ip.py
text: @user1:
Unfortunately this breaks ordering for the column (because the accessor is no longer tied to a discrete field). What we can do instead is pass a callable to `linkify` which will dynamically resolve the URL for the assigned object.

```suggestion
        accessor='assigned_object_id',
        linkify=lambda record: record.assigned_object.get_absolute_url(),
```