diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 569ea4942..77bb1d04b 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -29,6 +29,7 @@ * [#6130](https://github.com/netbox-community/netbox/issues/6130) - Improve display of assigned models in custom fields list * [#6155](https://github.com/netbox-community/netbox/issues/6155) - Fix admin links for plugins, background tasks * [#6171](https://github.com/netbox-community/netbox/issues/6171) - Fix display of horizontally-scrolling object lists +* [#6173](https://github.com/netbox-community/netbox/issues/6173) - Fix assigned device/VM count when bulk editing/deleting device roles --- diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 53e842ff9..5da50e0db 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -1172,14 +1172,20 @@ class DeviceRoleBulkImportView(generic.BulkImportView): class DeviceRoleBulkEditView(generic.BulkEditView): - queryset = DeviceRole.objects.all() + queryset = DeviceRole.objects.annotate( + device_count=count_related(Device, 'device_role'), + vm_count=count_related(VirtualMachine, 'role') + ) filterset = filters.DeviceRoleFilterSet table = tables.DeviceRoleTable form = forms.DeviceRoleBulkEditForm class DeviceRoleBulkDeleteView(generic.BulkDeleteView): - queryset = DeviceRole.objects.all() + queryset = DeviceRole.objects.annotate( + device_count=count_related(Device, 'device_role'), + vm_count=count_related(VirtualMachine, 'role') + ) table = tables.DeviceRoleTable