mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 07:56:44 -06:00
adds inventory item children view #14112
This commit is contained in:
parent
22e474ff96
commit
99926e43c3
@ -1283,3 +1283,10 @@ class InventoryItem(MPTTModel, ComponentModel, TrackingModelMixin):
|
|||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
"device": _("Cannot assign inventory item to component on another device")
|
"device": _("Cannot assign inventory item to component on another device")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@property
|
||||||
|
def children(self):
|
||||||
|
return InventoryItem.objects.filter(
|
||||||
|
device=self.device,
|
||||||
|
parent=self
|
||||||
|
)
|
||||||
|
@ -2993,6 +2993,25 @@ class InventoryItemBulkDeleteView(generic.BulkDeleteView):
|
|||||||
template_name = 'dcim/inventoryitem_bulk_delete.html'
|
template_name = 'dcim/inventoryitem_bulk_delete.html'
|
||||||
|
|
||||||
|
|
||||||
|
@register_model_view(InventoryItem, 'children')
|
||||||
|
class InventoryItemChildrenView(generic.ObjectChildrenView):
|
||||||
|
queryset = InventoryItem.objects.all()
|
||||||
|
child_model = InventoryItem
|
||||||
|
table = tables.InventoryItemTable
|
||||||
|
filterset = filtersets.InventoryItemFilterSet
|
||||||
|
template_name = 'generic/object_children.html'
|
||||||
|
tab = ViewTab(
|
||||||
|
label=_('Children'),
|
||||||
|
badge=lambda obj: obj.children.count(),
|
||||||
|
permission='dcim.view_inventoryitem',
|
||||||
|
hide_if_empty=True,
|
||||||
|
weight=5000
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_children(self, request, parent):
|
||||||
|
return parent.children.restrict(request.user, 'view')
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Inventory item roles
|
# Inventory item roles
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user