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:
@@ -1377,10 +1377,11 @@ class InventoryItemForm(CustomFieldModelForm):
|
||||
queryset=ContentType.objects.all(),
|
||||
limit_choices_to=MODULAR_COMPONENT_MODELS,
|
||||
required=False,
|
||||
widget=StaticSelect
|
||||
widget=forms.HiddenInput
|
||||
)
|
||||
component_id = forms.IntegerField(
|
||||
required=False
|
||||
required=False,
|
||||
widget=forms.HiddenInput
|
||||
)
|
||||
tags = DynamicModelMultipleChoiceField(
|
||||
queryset=Tag.objects.all(),
|
||||
@@ -1396,7 +1397,6 @@ class InventoryItemForm(CustomFieldModelForm):
|
||||
fieldsets = (
|
||||
('Inventory Item', ('device', 'parent', 'name', 'label', 'role', 'description', 'tags')),
|
||||
('Hardware', ('manufacturer', 'part_id', 'serial', 'asset_tag')),
|
||||
('Component', ('component_type', 'component_id')),
|
||||
)
|
||||
widgets = {
|
||||
'device': forms.HiddenInput(),
|
||||
|
@@ -781,6 +781,8 @@ class InventoryItemTable(DeviceComponentTable):
|
||||
linkify=True
|
||||
)
|
||||
component = tables.Column(
|
||||
accessor=Accessor('component'),
|
||||
orderable=False,
|
||||
linkify=True
|
||||
)
|
||||
discovered = BooleanColumn()
|
||||
@@ -792,8 +794,8 @@ class InventoryItemTable(DeviceComponentTable):
|
||||
class Meta(BaseTable.Meta):
|
||||
model = InventoryItem
|
||||
fields = (
|
||||
'pk', 'id', 'name', 'device', 'label', 'role', 'manufacturer', 'part_id', 'serial', 'asset_tag',
|
||||
'component', 'description', 'discovered', 'tags',
|
||||
'pk', 'id', 'name', 'device', 'component', 'label', 'role', 'manufacturer', 'part_id', 'serial',
|
||||
'asset_tag', 'description', 'discovered', 'tags',
|
||||
)
|
||||
default_columns = (
|
||||
'pk', 'name', 'device', 'label', 'role', 'manufacturer', 'part_id', 'serial', 'asset_tag',
|
||||
|
@@ -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):
|
||||
|
Reference in New Issue
Block a user