mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-15 11:42:52 -06:00
Allow exclusion of inherited contacts
This commit is contained in:
parent
d5316de9c8
commit
72adda1197
@ -364,9 +364,11 @@ class ContactsMixin(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def get_contacts(self):
|
def get_contacts(self, inherited=True):
|
||||||
"""
|
"""
|
||||||
Return a `QuerySet` matching all contacts assigned to this object.
|
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 tenancy.models import ContactAssignment
|
||||||
from . import NestedGroupModel
|
from . import NestedGroupModel
|
||||||
@ -377,7 +379,7 @@ class ContactsMixin(models.Model):
|
|||||||
object_type=ObjectType.objects.get_for_model(obj),
|
object_type=ObjectType.objects.get_for_model(obj),
|
||||||
object_id__in=(
|
object_id__in=(
|
||||||
obj.get_ancestors(include_self=True).values_list('pk', flat=True)
|
obj.get_ancestors(include_self=True).values_list('pk', flat=True)
|
||||||
if isinstance(obj, NestedGroupModel)
|
if (isinstance(obj, NestedGroupModel) and inherited)
|
||||||
else [obj.pk]
|
else [obj.pk]
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user