Fixes #8970: Permit nested inventory item templates on device types

This commit is contained in:
jeremystretch 2022-03-28 13:22:43 -04:00
parent 22908a12e9
commit 340ff82487
4 changed files with 36 additions and 34 deletions

View File

@ -151,6 +151,7 @@ Where it is desired to limit the range of available VLANs within a group, users
* [#8845](https://github.com/netbox-community/netbox/issues/8845) - Correct default ASN formatting in table * [#8845](https://github.com/netbox-community/netbox/issues/8845) - Correct default ASN formatting in table
* [#8869](https://github.com/netbox-community/netbox/issues/8869) - Fix NoReverseMatch exception when displaying tag w/assignments * [#8869](https://github.com/netbox-community/netbox/issues/8869) - Fix NoReverseMatch exception when displaying tag w/assignments
* [#8872](https://github.com/netbox-community/netbox/issues/8872) - Enable filtering by custom object fields * [#8872](https://github.com/netbox-community/netbox/issues/8872) - Enable filtering by custom object fields
* [#8970](https://github.com/netbox-community/netbox/issues/8970) - Permit nested inventory item templates on device types
### Other Changes ### Other Changes

View File

@ -1025,10 +1025,10 @@ class DeviceBayTemplateForm(BootstrapMixin, forms.ModelForm):
class InventoryItemTemplateForm(BootstrapMixin, forms.ModelForm): class InventoryItemTemplateForm(BootstrapMixin, forms.ModelForm):
parent = DynamicModelChoiceField( parent = DynamicModelChoiceField(
queryset=InventoryItem.objects.all(), queryset=InventoryItemTemplate.objects.all(),
required=False, required=False,
query_params={ query_params={
'device_id': '$device' 'devicetype_id': '$device_type'
} }
) )
role = DynamicModelChoiceField( role = DynamicModelChoiceField(
@ -1050,11 +1050,6 @@ class InventoryItemTemplateForm(BootstrapMixin, forms.ModelForm):
widget=forms.HiddenInput widget=forms.HiddenInput
) )
fieldsets = (
('Inventory Item', ('device_type', 'parent', 'name', 'label', 'role', 'description')),
('Hardware', ('manufacturer', 'part_id')),
)
class Meta: class Meta:
model = InventoryItemTemplate model = InventoryItemTemplate
fields = [ fields = [

View File

@ -241,5 +241,7 @@ class InventoryItemTemplateTable(ComponentTemplateTable):
class Meta(ComponentTemplateTable.Meta): class Meta(ComponentTemplateTable.Meta):
model = InventoryItemTemplate model = InventoryItemTemplate
fields = ('pk', 'name', 'label', 'role', 'manufacturer', 'part_id', 'component', 'description', 'actions') fields = (
'pk', 'name', 'label', 'parent', 'role', 'manufacturer', 'part_id', 'component', 'description', 'actions',
)
empty_text = "None" empty_text = "None"

View File

@ -2,33 +2,37 @@
{% load form_helpers %} {% load form_helpers %}
{% block form %} {% block form %}
<div class="row mb-2"> {% if form.module_type %}
<div class="offset-sm-3"> <div class="row mb-2">
<ul class="nav nav-pills" role="tablist"> <div class="offset-sm-3">
<li role="presentation" class="nav-item"> <ul class="nav nav-pills" role="tablist">
<button role="tab" type="button" id="devicetype_tab" data-bs-toggle="tab" aria-controls="devicetype" data-bs-target="#devicetype" class="nav-link {% if not form.initial.module_type %}active{% endif %}"> <li role="presentation" class="nav-item">
Device Type <button role="tab" type="button" id="devicetype_tab" data-bs-toggle="tab" aria-controls="devicetype" data-bs-target="#devicetype" class="nav-link {% if not form.initial.module_type %}active{% endif %}">
</button> Device Type
</li> </button>
<li role="presentation" class="nav-item"> </li>
<button role="tab" type="button" id="moduletype_tab" data-bs-toggle="tab" aria-controls="moduletype" data-bs-target="#moduletype" class="nav-link {% if form.initial.module_type %}active{% endif %}"> <li role="presentation" class="nav-item">
Module Type <button role="tab" type="button" id="moduletype_tab" data-bs-toggle="tab" aria-controls="moduletype" data-bs-target="#moduletype" class="nav-link {% if form.initial.module_type %}active{% endif %}">
</button> Module Type
</li> </button>
</ul> </li>
</ul>
</div>
</div> </div>
</div> <div class="tab-content p-0 border-0">
<div class="tab-content p-0 border-0"> <div class="tab-pane {% if not form.initial.module_type %}active{% endif %}" id="devicetype" role="tabpanel">
<div class="tab-pane {% if not form.initial.module_type %}active{% endif %}" id="devicetype" role="tabpanel"> {% render_field replication_form.device_type %}
{% render_field replication_form.device_type %} </div>
<div class="tab-pane {% if form.initial.module_type %}active{% endif %}" id="moduletype" role="tabpanel">
{% render_field replication_form.module_type %}
</div>
</div> </div>
<div class="tab-pane {% if form.initial.module_type %}active{% endif %}" id="moduletype" role="tabpanel"> {% else %}
{% render_field replication_form.module_type %} {% render_field replication_form.device_type %}
</div> {% endif %}
{% block replication_fields %} {% block replication_fields %}
{% render_field replication_form.name_pattern %} {% render_field replication_form.name_pattern %}
{% render_field replication_form.label_pattern %} {% render_field replication_form.label_pattern %}
{% endblock replication_fields %} {% endblock replication_fields %}
</div>
{{ block.super }} {{ block.super }}
{% endblock form %} {% endblock form %}