1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #12715: Use contact assignments table to display the contacts assigned to an object

This commit is contained in:
jeremystretch
2023-05-30 14:51:16 -04:00
parent 18c863e393
commit b3bd03a1e9
2 changed files with 18 additions and 10 deletions

View File

@@ -15,25 +15,32 @@ from .models import *
class ObjectContactsView(generic.ObjectChildrenView):
child_model = Contact
table = tables.ContactTable
filterset = filtersets.ContactFilterSet
child_model = ContactAssignment
table = tables.ContactAssignmentTable
filterset = filtersets.ContactAssignmentFilterSet
template_name = 'tenancy/object_contacts.html'
tab = ViewTab(
label=_('Contacts'),
badge=lambda obj: obj.contacts.count(),
permission='tenancy.view_contact',
permission='tenancy.view_contactassignment',
weight=5000
)
def get_children(self, request, parent):
return Contact.objects.annotate(
assignment_count=count_related(ContactAssignment, 'contact')
).restrict(request.user, 'view').filter(
assignments__content_type=ContentType.objects.get_for_model(parent),
assignments__object_id=parent.pk
return ContactAssignment.objects.restrict(request.user, 'view').filter(
content_type=ContentType.objects.get_for_model(parent),
object_id=parent.pk
)
def get_table(self, *args, **kwargs):
table = super().get_table(*args, **kwargs)
# Hide object columns
table.columns.hide('content_type')
table.columns.hide('object')
return table
def get_extra_context(self, request, instance):
return {
'base_template': f'{instance._meta.app_label}/{instance._meta.model_name}.html',