1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#7846: Show assigned component (if any) when creating inventory item

This commit is contained in:
jeremystretch
2021-12-28 14:06:20 -05:00
parent e9910d1fe2
commit 21356b487a
5 changed files with 44 additions and 7 deletions

View File

@ -2399,6 +2399,18 @@ class InventoryItemEditView(generic.ObjectEditView):
class InventoryItemCreateView(generic.ComponentCreateView):
queryset = InventoryItem.objects.all()
model_form = forms.InventoryItemForm
template_name = 'dcim/inventoryitem_create.html'
def alter_object(self, instance, request):
# Set component (if any)
component_type = request.GET.get('component_type')
component_id = request.GET.get('component_id')
if component_type and component_id:
content_type = get_object_or_404(ContentType, pk=component_type)
instance.component = get_object_or_404(content_type.model_class(), pk=component_id)
return instance
class InventoryItemDeleteView(generic.ObjectDeleteView):