mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-23 17:08:41 -06:00
Show parent contacts for nested models
When contacts of a nested model are displayed, the contacts of the parents are also displayed.
This commit is contained in:
parent
697610db94
commit
701f40e2a8
@ -2,6 +2,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from netbox.models import NestedGroupModel
|
||||||
from netbox.views import generic
|
from netbox.views import generic
|
||||||
from utilities.query import count_related
|
from utilities.query import count_related
|
||||||
from utilities.views import GetRelatedModelsMixin, ViewTab, register_model_view
|
from utilities.views import GetRelatedModelsMixin, ViewTab, register_model_view
|
||||||
@ -23,19 +24,18 @@ class ObjectContactsView(generic.ObjectChildrenView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_children(self, request, parent):
|
def get_children(self, request, parent):
|
||||||
return ContactAssignment.objects.restrict(request.user, 'view').filter(
|
qs = ContactAssignment.objects.restrict(request.user, 'view')
|
||||||
object_type=ContentType.objects.get_for_model(parent),
|
for obj in [parent]:
|
||||||
object_id=parent.pk
|
qs = qs.filter(
|
||||||
).order_by('priority', 'contact', 'role')
|
object_type=ContentType.objects.get_for_model(obj),
|
||||||
|
object_id__in=(
|
||||||
|
obj.get_ancestors(include_self=True).values_list('pk', flat=True)
|
||||||
|
if isinstance(obj, NestedGroupModel)
|
||||||
|
else [obj.pk]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
def get_table(self, *args, **kwargs):
|
return qs.order_by('priority', 'contact', 'role')
|
||||||
table = super().get_table(*args, **kwargs)
|
|
||||||
|
|
||||||
# Hide object columns
|
|
||||||
table.columns.hide('object_type')
|
|
||||||
table.columns.hide('object')
|
|
||||||
|
|
||||||
return table
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user