Skip to content

Commit

Permalink
Limit inherited contacts to model
Browse files Browse the repository at this point in the history
  • Loading branch information
alehaa committed Feb 21, 2025
1 parent 72adda1 commit ca6b686
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions netbox/netbox/models/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,14 @@ def get_contacts(self, inherited=True):
from tenancy.models import ContactAssignment
from . import NestedGroupModel

filter = Q()
for obj in [self]:
filter |= Q(
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) and inherited)
else [obj.pk]
),
)
filter = Q(
object_type=ObjectType.objects.get_for_model(self),
object_id__in=(
self.get_ancestors(include_self=True).values_list('pk', flat=True)
if (isinstance(self, NestedGroupModel) and inherited)
else [self.pk]
),
)

return ContactAssignment.objects.filter(filter)

Expand Down

0 comments on commit ca6b686

Please sign in to comment.