[PR #15876] [MERGED] 15794 Make "related objects" dynamic #14702

Closed
opened 2025-12-29 23:26:10 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/15876
Author: @alehaa
Created: 4/28/2024
Status: Merged
Merged: 6/12/2024
Merged by: @jeremystretch

Base: developHead: feature/15794-related-objects


📝 Commits (9)

  • 78f741f Closes #15794: Make "related objects" dynamic
  • f82e362 Fix related models call
  • 6b13fec Merge branch 'develop' into feature/15794-related-objects
  • 1218bf1 Remove extra related models hook
  • 4c41db0 Merge branch 'develop' into feature/15794-related-objects
  • a2aa40d Merge branch 'develop' into feature/15794-related-objects
  • 053fa9f Fix relations view for ASNs
  • 9b5ca90 Add method call keywords for clarification
  • 5277687 Cleanup related models

📊 Changes

9 files changed (+176 additions, -238 deletions)

View changed files

📝 netbox/circuits/views.py (+18 -29)
📝 netbox/core/views.py (+3 -7)
📝 netbox/dcim/views.py (+73 -116)
📝 netbox/ipam/views.py (+18 -35)
📝 netbox/tenancy/views.py (+9 -25)
📝 netbox/utilities/views.py (+44 -0)
📝 netbox/virtualization/views.py (+5 -13)
📝 netbox/vpn/views.py (+3 -7)
📝 netbox/wireless/views.py (+3 -6)

📄 Description

Fixes: #15794

Instead of hardcoding relationships between models for the detail view, they are now dynamically generated.

Known limitations

  1. If a related model doesn't have a list view, rendering of the related objects pane will fail. This limitation was already present before, but related models listed were explicitly chosen to do so. For all views shipped with NetBox I've added a filter if needed (omit parameter). However, external plugins might trigger this unintentionally, when named view is not available, but the relationship has not been setup with related_name='+' parameter. Switching to verified_view in the panel's template should resolve this, but might decrease performance slightly.

  2. If a model introduces several relations to another model, they will all be listed with the same model name but different URL query parameters. This is not the case for models included in NetBox. As before, plugin developers can still use an extra panel for this special purpose and extra context about the different types of relationships.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/15876 **Author:** [@alehaa](https://github.com/alehaa) **Created:** 4/28/2024 **Status:** ✅ Merged **Merged:** 6/12/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `feature/15794-related-objects` --- ### 📝 Commits (9) - [`78f741f`](https://github.com/netbox-community/netbox/commit/78f741f85661267441ec5b4c89a05183d0db373f) Closes #15794: Make "related objects" dynamic - [`f82e362`](https://github.com/netbox-community/netbox/commit/f82e362d96563a747543831200d688fdf6a0d237) Fix related models call - [`6b13fec`](https://github.com/netbox-community/netbox/commit/6b13fec7b8c343472336c7d50f00f422ae9cab1a) Merge branch 'develop' into feature/15794-related-objects - [`1218bf1`](https://github.com/netbox-community/netbox/commit/1218bf188bb89e8414d4a2ba1900ffaa27cff5cc) Remove extra related models hook - [`4c41db0`](https://github.com/netbox-community/netbox/commit/4c41db018426f94d75f42fac2d7bf83439805715) Merge branch 'develop' into feature/15794-related-objects - [`a2aa40d`](https://github.com/netbox-community/netbox/commit/a2aa40d8faa3927f0b422078e73f6ffc9c096c73) Merge branch 'develop' into feature/15794-related-objects - [`053fa9f`](https://github.com/netbox-community/netbox/commit/053fa9fdea9eb9c25ca83b564e489cda01315da3) Fix relations view for ASNs - [`9b5ca90`](https://github.com/netbox-community/netbox/commit/9b5ca90c27813e55b53310ff1126d7613cf5846b) Add method call keywords for clarification - [`5277687`](https://github.com/netbox-community/netbox/commit/5277687d844110abaa4eeb464c7cc3eb453e7bcd) Cleanup related models ### 📊 Changes **9 files changed** (+176 additions, -238 deletions) <details> <summary>View changed files</summary> 📝 `netbox/circuits/views.py` (+18 -29) 📝 `netbox/core/views.py` (+3 -7) 📝 `netbox/dcim/views.py` (+73 -116) 📝 `netbox/ipam/views.py` (+18 -35) 📝 `netbox/tenancy/views.py` (+9 -25) 📝 `netbox/utilities/views.py` (+44 -0) 📝 `netbox/virtualization/views.py` (+5 -13) 📝 `netbox/vpn/views.py` (+3 -7) 📝 `netbox/wireless/views.py` (+3 -6) </details> ### 📄 Description <!-- 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: #15794 <!-- Please include a summary of the proposed changes below. --> Instead of hardcoding relationships between models for the detail view, they are now dynamically generated. #### Known limitations 1. If a related model doesn't have a `list` view, rendering of the [related objects pane](https://github.com/netbox-community/netbox/blob/85db007ff585370b03b2d88d8f43e6fa9b94bc8e/netbox/templates/inc/panels/related_objects.html#L8) will fail. This limitation was already present before, but related models listed were explicitly chosen to do so. For all views shipped with NetBox I've added a filter if needed (`omit` parameter). However, external plugins might trigger this unintentionally, when named view is not available, but the relationship has not been setup with `related_name='+'` parameter. Switching to `verified_view` in the panel's template should resolve this, but might decrease performance slightly. 2. If a model introduces several relations to another model, they will all be listed with the same model name but different URL query parameters. This is not the case for models included in NetBox. As before, plugin developers can still use an extra panel for this special purpose and extra context about the different types of relationships. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:26:10 +01:00
adam closed this issue 2025-12-29 23:26:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14702