Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

15794 Make "related objects" dynamic #15876

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

alehaa
Copy link
Contributor

@alehaa alehaa commented Apr 28, 2024

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.

Instead of hardcoding relationships between models for the detail view,
they are now dynamically generated.
Provides logic for collecting all related models for the currently viewed model.
"""

def get_extra_related_models(self, request, instance):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this method? It seems like maybe a hook for monkey patching, which IMO should be discouraged. If needed, we could potentially extend the underlying get_related_models() utility function (not the class method) to collect additional types of relationships.

Or, if it's intended to be overridden naturally, we could introduce an extra keyword argument to the get_related_models() method to pass these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, its intended to be used as a hook by view classes, e.g. when not only direct relations should be collected.

Although I prefer a generic approach that implements some logic in the utility function, I don't know how we should determine which transient relations are interesting for object views. So for now, I'd remove this method and add an extra keyword argument to the class method instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the "Related Objects" pane of all models dynamic
2 participants