mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Fixes #12715: Use contact assignments table to display the contacts assigned to an object
This commit is contained in:
parent
18c863e393
commit
b3bd03a1e9
@ -12,9 +12,10 @@
|
||||
|
||||
* [#11539](https://github.com/netbox-community/netbox/issues/11539) - Fix exception when applying "empty" filter lookup with invalid value
|
||||
* [#11934](https://github.com/netbox-community/netbox/issues/11934) - Prevent reassignment of an IP address designated as primary for its parent object
|
||||
* [#12370](https://github.com/netbox-community/netbox/issues/12370) - Fix extraneous contacts listed in object contact assignments view
|
||||
* [#12730](https://github.com/netbox-community/netbox/issues/12730) - Fix extraneous contacts listed in object contact assignments view
|
||||
* [#12627](https://github.com/netbox-community/netbox/issues/12627) - Restore hover preview for embedded image attachment tables
|
||||
* [#12694](https://github.com/netbox-community/netbox/issues/12694) - Strip leading & trailing whitespace from custom link URL & text
|
||||
* [#12715](https://github.com/netbox-community/netbox/issues/12715) - Use contact assignments table to display the contacts assigned to an object
|
||||
* [#12745](https://github.com/netbox-community/netbox/issues/12745) - Escape display text in API-backed selection widgets
|
||||
|
||||
---
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user