mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-21 21:02:23 -06:00
15794 Make "related objects" dynamic (#15876)
* Closes #15794: Make "related objects" dynamic Instead of hardcoding relationships between models for the detail view, they are now dynamically generated. * Fix related models call * Remove extra related models hook Instead of providing a rarely used hook method, additional related models can now be passed directly to the lookup method. * Fix relations view for ASNs ASNs have ManyToMany relationships and therefore can't used automatic resolving. Explicit relations have been restored as before. * Add method call keywords for clarification * Cleanup related models --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
@@ -2,7 +2,7 @@ from ipam.tables import RouteTargetTable
|
||||
from netbox.views import generic
|
||||
from tenancy.views import ObjectContactsView
|
||||
from utilities.query import count_related
|
||||
from utilities.views import register_model_view
|
||||
from utilities.views import GetRelatedModelsMixin, register_model_view
|
||||
from . import filtersets, forms, tables
|
||||
from .models import *
|
||||
|
||||
@@ -21,16 +21,12 @@ class TunnelGroupListView(generic.ObjectListView):
|
||||
|
||||
|
||||
@register_model_view(TunnelGroup)
|
||||
class TunnelGroupView(generic.ObjectView):
|
||||
class TunnelGroupView(GetRelatedModelsMixin, generic.ObjectView):
|
||||
queryset = TunnelGroup.objects.all()
|
||||
|
||||
def get_extra_context(self, request, instance):
|
||||
related_models = (
|
||||
(Tunnel.objects.restrict(request.user, 'view').filter(group=instance), 'group_id'),
|
||||
)
|
||||
|
||||
return {
|
||||
'related_models': related_models,
|
||||
'related_models': self.get_related_models(request, instance),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user