From e0ebb8e7d894ab57594f37baceb9ee1b6624927a Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 13 May 2020 17:08:48 -0400 Subject: [PATCH] Fixes #4617: Restore IP prefix depth notation in list view --- docs/release-notes/version-2.8.md | 1 + netbox/ipam/tables.py | 2 ++ netbox/utilities/tables.py | 9 +++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-2.8.md b/docs/release-notes/version-2.8.md index 914f17cf7..17e04dad3 100644 --- a/docs/release-notes/version-2.8.md +++ b/docs/release-notes/version-2.8.md @@ -12,6 +12,7 @@ v2.8.4 (FUTURE) * [#4604](https://github.com/netbox-community/netbox/issues/4604) - Multi-position rear ports may only be connected to other rear ports * [#4607](https://github.com/netbox-community/netbox/issues/4607) - Missing Contextual help for API Tokens * [#4613](https://github.com/netbox-community/netbox/issues/4613) - Fix tag assignment on config contexts (regression from #4527) +* [#4617](https://github.com/netbox-community/netbox/issues/4617) - Restore IP prefix depth notation in list view * [#4629](https://github.com/netbox-community/netbox/issues/4629) - Replicate assigned interface when cloning IP addresses * [#4633](https://github.com/netbox-community/netbox/issues/4633) - Bump django-rq to v2.3.2 to fix ImportError with rq 1.4.0 * [#4634](https://github.com/netbox-community/netbox/issues/4634) - Inventory Item List view exception caused by incorrect accessor definition diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index 23bf14653..d8b50c11d 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -378,6 +378,8 @@ class PrefixTable(BaseTable): verbose_name='Pool' ) + add_prefetch = False + class Meta(BaseTable.Meta): model = Prefix fields = ('pk', 'prefix', 'status', 'vrf', 'tenant', 'site', 'vlan', 'role', 'is_pool', 'description') diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py index 0702936b5..97108b5b2 100644 --- a/netbox/utilities/tables.py +++ b/netbox/utilities/tables.py @@ -1,6 +1,5 @@ import django_tables2 as tables from django.core.exceptions import FieldDoesNotExist -from django.db.models import ForeignKey from django.db.models.fields.related import RelatedField from django.utils.safestring import mark_safe from django_tables2.data import TableQuerysetData @@ -9,7 +8,13 @@ from django_tables2.data import TableQuerysetData class BaseTable(tables.Table): """ Default table for object lists + + :param add_prefetch: By default, modify the queryset passed to the table upon initialization to automatically + prefetch related data. Set this to False if it's necessary to avoid modifying the queryset (e.g. to + accommodate PrefixQuerySet.annotate_depth()). """ + add_prefetch = True + class Meta: attrs = { 'class': 'table table-hover table-headings', @@ -50,7 +55,7 @@ class BaseTable(tables.Table): self.sequence.append('actions') # Dynamically update the table's QuerySet to ensure related fields are pre-fetched - if isinstance(self.data, TableQuerysetData): + if self.add_prefetch and isinstance(self.data, TableQuerysetData): model = getattr(self.Meta, 'model') prefetch_fields = [] for column in self.columns: