Jeremy Stretch 1 год назад
Родитель
Сommit
047d717532
2 измененных файлов с 26 добавлено и 10 удалено
  1. 23 9
      netbox/dcim/tables/racks.py
  2. 3 1
      netbox/dcim/views.py

+ 23 - 9
netbox/dcim/tables/racks.py

@@ -84,6 +84,11 @@ class RackTypeTable(NetBoxTable):
     comments = columns.MarkdownColumn(
     comments = columns.MarkdownColumn(
         verbose_name=_('Comments'),
         verbose_name=_('Comments'),
     )
     )
+    instance_count = columns.LinkedCountColumn(
+        viewname='dcim:rack_list',
+        url_params={'rack_type_id': 'pk'},
+        verbose_name=_('Instances')
+    )
     tags = columns.TagColumn(
     tags = columns.TagColumn(
         url_name='dcim:rack_list'
         url_name='dcim:rack_list'
     )
     )
@@ -92,11 +97,11 @@ class RackTypeTable(NetBoxTable):
         model = RackType
         model = RackType
         fields = (
         fields = (
             'pk', 'id', 'name', 'manufacturer', 'form_factor', 'u_height', 'starting_unit', 'width', 'outer_width',
             'pk', 'id', 'name', 'manufacturer', 'form_factor', 'u_height', 'starting_unit', 'width', 'outer_width',
-            'outer_depth', 'mounting_depth', 'airflow', 'weight', 'max_weight', 'description', 'comments', 'tags',
-            'created', 'last_updated',
+            'outer_depth', 'mounting_depth', 'airflow', 'weight', 'max_weight', 'description', 'comments',
+            'instance_count', 'tags', 'created', 'last_updated',
         )
         )
         default_columns = (
         default_columns = (
-            'pk', 'name', 'manufacturer', 'type', 'u_height', 'description',
+            'pk', 'name', 'manufacturer', 'type', 'u_height', 'description', 'instance_count',
         )
         )
 
 
 
 
@@ -124,6 +129,15 @@ class RackTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
     role = columns.ColoredLabelColumn(
     role = columns.ColoredLabelColumn(
         verbose_name=_('Role'),
         verbose_name=_('Role'),
     )
     )
+    manufacturer = tables.Column(
+        verbose_name=_('Manufacturer'),
+        accessor=Accessor('rack_type__manufacturer'),
+        linkify=True
+    )
+    rack_type = tables.Column(
+        linkify=True,
+        verbose_name=_('Type')
+    )
     u_height = tables.TemplateColumn(
     u_height = tables.TemplateColumn(
         template_code="{{ value }}U",
         template_code="{{ value }}U",
         verbose_name=_('Height')
         verbose_name=_('Height')
@@ -169,14 +183,14 @@ class RackTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
     class Meta(NetBoxTable.Meta):
     class Meta(NetBoxTable.Meta):
         model = Rack
         model = Rack
         fields = (
         fields = (
-            'pk', 'id', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'tenant_group', 'role', 'serial',
-            'asset_tag', 'form_factor', 'u_height', 'starting_unit', 'width', 'outer_width', 'outer_depth',
-            'mounting_depth', 'airflow', 'weight', 'max_weight', 'comments', 'device_count', 'get_utilization',
-            'get_power_utilization', 'description', 'contacts', 'tags', 'created', 'last_updated',
+            'pk', 'id', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'tenant_group', 'role',
+            'rack_type', 'serial', 'asset_tag', 'form_factor', 'u_height', 'starting_unit', 'width', 'outer_width',
+            'outer_depth', 'mounting_depth', 'airflow', 'weight', 'max_weight', 'comments', 'device_count',
+            'get_utilization', 'get_power_utilization', 'description', 'contacts', 'tags', 'created', 'last_updated',
         )
         )
         default_columns = (
         default_columns = (
-            'pk', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'role', 'u_height', 'device_count',
-            'get_utilization',
+            'pk', 'name', 'site', 'location', 'status', 'facility_id', 'tenant', 'role', 'rack_type', 'u_height',
+            'device_count', 'get_utilization',
         )
         )
 
 
 
 

+ 3 - 1
netbox/dcim/views.py

@@ -584,7 +584,9 @@ class RackRoleBulkDeleteView(generic.BulkDeleteView):
 #
 #
 
 
 class RackTypeListView(generic.ObjectListView):
 class RackTypeListView(generic.ObjectListView):
-    queryset = RackType.objects.all()
+    queryset = RackType.objects.annotate(
+        instance_count=count_related(Rack, 'rack_type')
+    )
     filterset = filtersets.RackTypeFilterSet
     filterset = filtersets.RackTypeFilterSet
     filterset_form = forms.RackTypeFilterForm
     filterset_form = forms.RackTypeFilterForm
     table = tables.RackTypeTable
     table = tables.RackTypeTable