mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 07:56:44 -06:00
Use existing child_items relation
This commit is contained in:
parent
99926e43c3
commit
4dddd8666e
@ -1283,10 +1283,3 @@ 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
|
|
||||||
)
|
|
||||||
|
@ -3002,14 +3002,14 @@ class InventoryItemChildrenView(generic.ObjectChildrenView):
|
|||||||
template_name = 'generic/object_children.html'
|
template_name = 'generic/object_children.html'
|
||||||
tab = ViewTab(
|
tab = ViewTab(
|
||||||
label=_('Children'),
|
label=_('Children'),
|
||||||
badge=lambda obj: obj.children.count(),
|
badge=lambda obj: obj.child_items.count(),
|
||||||
permission='dcim.view_inventoryitem',
|
permission='dcim.view_inventoryitem',
|
||||||
hide_if_empty=True,
|
hide_if_empty=True,
|
||||||
weight=5000
|
weight=5000
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_children(self, request, parent):
|
def get_children(self, request, parent):
|
||||||
return parent.children.restrict(request.user, 'view')
|
return parent.child_items.restrict(request.user, 'view')
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user