Closes #1824: Add virtual machine count to platforms list

This commit is contained in:
Jeremy Stretch 2018-01-19 09:25:16 -05:00
parent d5ecfe7bef
commit 7ac27b59c6
2 changed files with 11 additions and 4 deletions

View File

@ -381,13 +381,17 @@ class PlatformTable(BaseTable):
pk = ToggleColumn()
name = tables.LinkColumn(verbose_name='Name')
device_count = tables.Column(verbose_name='Devices')
vm_count = tables.Column(verbose_name='VMs')
slug = tables.Column(verbose_name='Slug')
actions = tables.TemplateColumn(template_code=PLATFORM_ACTIONS, attrs={'td': {'class': 'text-right'}},
verbose_name='')
actions = tables.TemplateColumn(
template_code=PLATFORM_ACTIONS,
attrs={'td': {'class': 'text-right'}},
verbose_name=''
)
class Meta(BaseTable.Meta):
model = Platform
fields = ('pk', 'name', 'device_count', 'slug', 'napalm_driver', 'actions')
fields = ('pk', 'name', 'device_count', 'vm_count', 'slug', 'napalm_driver', 'actions')
#

View File

@ -754,7 +754,10 @@ class DeviceRoleBulkDeleteView(PermissionRequiredMixin, BulkDeleteView):
#
class PlatformListView(ObjectListView):
queryset = Platform.objects.annotate(device_count=Count('devices'))
queryset = Platform.objects.annotate(
device_count=Count('devices', distinct=True),
vm_count=Count('virtual_machines', distinct=True)
)
table = tables.PlatformTable
template_name = 'dcim/platform_list.html'