From 72adda11974f81fbc0cc9edfc74654009c74b1b9 Mon Sep 17 00:00:00 2001 From: Alexander Haase Date: Tue, 18 Feb 2025 23:08:47 +0100 Subject: [PATCH] Allow exclusion of inherited contacts --- netbox/netbox/models/features.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/netbox/netbox/models/features.py b/netbox/netbox/models/features.py index 70027a9fc..ba895d5ed 100644 --- a/netbox/netbox/models/features.py +++ b/netbox/netbox/models/features.py @@ -364,9 +364,11 @@ class ContactsMixin(models.Model): class Meta: abstract = True - def get_contacts(self): + def get_contacts(self, inherited=True): """ Return a `QuerySet` matching all contacts assigned to this object. + + :param inherited: If `True`, inherited contacts from parent objects are included. """ from tenancy.models import ContactAssignment from . import NestedGroupModel @@ -377,7 +379,7 @@ class ContactsMixin(models.Model): object_type=ObjectType.objects.get_for_model(obj), object_id__in=( obj.get_ancestors(include_self=True).values_list('pk', flat=True) - if isinstance(obj, NestedGroupModel) + if (isinstance(obj, NestedGroupModel) and inherited) else [obj.pk] ), )