Skip to content

Commit

Permalink
Merge pull request #8 from DanSheps/develop
Browse files Browse the repository at this point in the history
Fixes: #6 - Show device count on Hardware Lifecycle list view
  • Loading branch information
DanSheps authored Mar 20, 2024
2 parents be042da + ce7c20b commit b96651b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 7 additions & 1 deletion netbox_lifecycle/models/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db import models
from django.urls import reverse

from dcim.models import DeviceType, ModuleType
from dcim.models import DeviceType, ModuleType, Device, Module
from netbox.models import NetBoxModel


Expand Down Expand Up @@ -58,5 +58,11 @@ def __str__(self):
return f'Module Type: {self.assigned_object.model}'
return f'Device Type: {self.assigned_object.model}'

@property
def assigned_object_count(self):
if isinstance(self.assigned_object, DeviceType):
return Device.objects.filter(device_type=self.assigned_object).count()
return Module.objects.filter(module_type=self.assigned_object).count()

def get_absolute_url(self):
return reverse('plugins:netbox_lifecycle:hardwarelifecycle', args=[self.pk])
5 changes: 2 additions & 3 deletions netbox_lifecycle/tables/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ class HardwareLifecycleTable(NetBoxTable):
linkify=True,
verbose_name='Hardware'
)
devices = tables.Column(
accessor=tables.A('devices__count'),
verbose_name='Device Count'
assigned_object_count = tables.Column(
verbose_name='Assigned Object Count'
)

class Meta(NetBoxTable.Meta):
Expand Down
2 changes: 1 addition & 1 deletion netbox_lifecycle/views/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from netbox_lifecycle.forms.model_forms import HardwareLifecycleForm
from netbox_lifecycle.models import HardwareLifecycle
from netbox_lifecycle.tables import HardwareLifecycleTable
from utilities.views import ViewTab, register_model_view
from utilities.views import register_model_view


__all__ = (
Expand Down

0 comments on commit b96651b

Please sign in to comment.