From d6c8d1581c665f2a6ae05c338ce3f94747732a30 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 27 Dec 2023 11:49:13 -0500 Subject: [PATCH] Closes #11039: List parent prefixes under IP range view --- netbox/ipam/views.py | 20 ++++++++++++++++++++ netbox/templates/ipam/iprange.html | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 1de53b6d2..5fc4301bb 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -661,6 +661,26 @@ class IPRangeListView(generic.ObjectListView): class IPRangeView(generic.ObjectView): queryset = IPRange.objects.all() + def get_extra_context(self, request, instance): + + # Parent prefixes table + parent_prefixes = Prefix.objects.restrict(request.user, 'view').filter( + Q(prefix__net_contains_or_equals=str(instance.start_address.ip)), + Q(prefix__net_contains_or_equals=str(instance.end_address.ip)), + vrf=instance.vrf + ).prefetch_related( + 'site', 'role', 'tenant', 'vlan', 'role' + ) + parent_prefixes_table = tables.PrefixTable( + list(parent_prefixes), + exclude=('vrf', 'utilization'), + orderable=False + ) + + return { + 'parent_prefixes_table': parent_prefixes_table, + } + @register_model_view(IPRange, 'ipaddresses', path='ip-addresses') class IPRangeIPAddressesView(generic.ObjectChildrenView): diff --git a/netbox/templates/ipam/iprange.html b/netbox/templates/ipam/iprange.html index 3e79e6690..13bfe4902 100644 --- a/netbox/templates/ipam/iprange.html +++ b/netbox/templates/ipam/iprange.html @@ -82,6 +82,11 @@ {% plugin_right_page object %} +
+
+ {% include 'inc/panel_table.html' with table=parent_prefixes_table heading='Parent Prefixes' %} +
+
{% plugin_full_width_page object %}