Skip to content

Commit

Permalink
Merge pull request #161 from alehaa/feature/columns
Browse files Browse the repository at this point in the history
Add device and module type columns
  • Loading branch information
matejv authored Jul 16, 2024
2 parents 3a220ef + b104dc8 commit d687fad
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions netbox_inventory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ class Asset(NetBoxModel, ImageAttachmentsMixin):
device_type = models.ForeignKey(
to='dcim.DeviceType',
on_delete=models.PROTECT,
related_name='+',
related_name='assets',
blank=True,
null=True,
verbose_name='Device Type',
)
module_type = models.ForeignKey(
to='dcim.ModuleType',
on_delete=models.PROTECT,
related_name='+',
related_name='assets',
blank=True,
null=True,
verbose_name='Module Type',
Expand Down
28 changes: 28 additions & 0 deletions netbox_inventory/tables.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from django.db.models.functions import Coalesce
import django_tables2 as tables
from django.utils.translation import gettext_lazy as _

from netbox.tables import columns, NetBoxTable
from tenancy.tables import ContactsColumnMixin
from .models import Asset, Delivery, InventoryItemType, InventoryItemGroup, Purchase, Supplier
from .template_content import WARRANTY_PROGRESSBAR

from dcim.tables import DeviceTypeTable, ModuleTypeTable
from utilities.tables import register_table_column

__all__ = (
'AssetTable',
'SupplierTable',
Expand Down Expand Up @@ -497,3 +501,27 @@ class Meta(NetBoxTable.Meta):
'asset_count',
'inventoryitem_type_count',
)


# ========================
# DCIM model table columns
# ========================

asset_count = columns.LinkedCountColumn(
viewname='plugins:netbox_inventory:asset_list',
url_params={'device_type_id': 'pk'},
verbose_name=_('Assets'),
accessor="assets__count",
)

register_table_column(asset_count, 'assets', DeviceTypeTable)


asset_count = columns.LinkedCountColumn(
viewname='plugins:netbox_inventory:asset_list',
url_params={'module_type_id': 'pk'},
verbose_name=_('Assets'),
accessor="assets__count",
)

register_table_column(asset_count, 'assets', ModuleTypeTable)

0 comments on commit d687fad

Please sign in to comment.