mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Use DynamicModelChoiceField for all fields using APISelect
This commit is contained in:
@@ -325,7 +325,7 @@ class SiteBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditFor
|
||||
required=False,
|
||||
widget=StaticSelect2()
|
||||
)
|
||||
tenant = forms.ModelChoiceField(
|
||||
tenant = DynamicModelChoiceField(
|
||||
queryset=Tenant.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -383,18 +383,20 @@ class SiteFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm):
|
||||
#
|
||||
|
||||
class RackGroupForm(BootstrapMixin, forms.ModelForm):
|
||||
site = DynamicModelChoiceField(
|
||||
queryset=Site.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/sites/"
|
||||
)
|
||||
)
|
||||
slug = SlugField()
|
||||
|
||||
class Meta:
|
||||
model = RackGroup
|
||||
fields = [
|
||||
fields = (
|
||||
'site', 'name', 'slug',
|
||||
]
|
||||
widgets = {
|
||||
'site': APISelect(
|
||||
api_url="/api/dcim/sites/"
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class RackGroupCSVForm(forms.ModelForm):
|
||||
@@ -471,6 +473,15 @@ class RackRoleCSVForm(forms.ModelForm):
|
||||
#
|
||||
|
||||
class RackForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
site = DynamicModelChoiceField(
|
||||
queryset=Site.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/sites/",
|
||||
filter_for={
|
||||
'group': 'site_id',
|
||||
}
|
||||
)
|
||||
)
|
||||
group = DynamicModelChoiceField(
|
||||
queryset=RackGroup.objects.all(),
|
||||
required=False,
|
||||
@@ -478,6 +489,13 @@ class RackForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
api_url='/api/dcim/rack-groups/',
|
||||
)
|
||||
)
|
||||
role = DynamicModelChoiceField(
|
||||
queryset=RackRole.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/rack-roles/',
|
||||
)
|
||||
)
|
||||
comments = CommentField()
|
||||
tags = TagField(
|
||||
required=False
|
||||
@@ -496,16 +514,7 @@ class RackForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
'u_height': "Height in rack units",
|
||||
}
|
||||
widgets = {
|
||||
'site': APISelect(
|
||||
api_url="/api/dcim/sites/",
|
||||
filter_for={
|
||||
'group': 'site_id',
|
||||
}
|
||||
),
|
||||
'status': StaticSelect2(),
|
||||
'role': APISelect(
|
||||
api_url="/api/dcim/rack-roles/"
|
||||
),
|
||||
'type': StaticSelect2(),
|
||||
'width': StaticSelect2(),
|
||||
'outer_unit': StaticSelect2(),
|
||||
@@ -605,7 +614,7 @@ class RackBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditFor
|
||||
queryset=Rack.objects.all(),
|
||||
widget=forms.MultipleHiddenInput
|
||||
)
|
||||
site = forms.ModelChoiceField(
|
||||
site = DynamicModelChoiceField(
|
||||
queryset=Site.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -615,14 +624,14 @@ class RackBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditFor
|
||||
}
|
||||
)
|
||||
)
|
||||
group = forms.ModelChoiceField(
|
||||
group = DynamicModelChoiceField(
|
||||
queryset=RackGroup.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/rack-groups",
|
||||
)
|
||||
)
|
||||
tenant = forms.ModelChoiceField(
|
||||
tenant = DynamicModelChoiceField(
|
||||
queryset=Tenant.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -635,7 +644,7 @@ class RackBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditFor
|
||||
initial='',
|
||||
widget=StaticSelect2()
|
||||
)
|
||||
role = forms.ModelChoiceField(
|
||||
role = DynamicModelChoiceField(
|
||||
queryset=RackRole.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -833,7 +842,7 @@ class RackReservationBulkEditForm(BootstrapMixin, BulkEditForm):
|
||||
required=False,
|
||||
widget=StaticSelect2()
|
||||
)
|
||||
tenant = forms.ModelChoiceField(
|
||||
tenant = DynamicModelChoiceField(
|
||||
queryset=Tenant.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -905,6 +914,12 @@ class ManufacturerCSVForm(forms.ModelForm):
|
||||
#
|
||||
|
||||
class DeviceTypeForm(BootstrapMixin, CustomFieldModelForm):
|
||||
manufacturer = DynamicModelChoiceField(
|
||||
queryset=Manufacturer.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/manufacturers/",
|
||||
)
|
||||
)
|
||||
slug = SlugField(
|
||||
slug_source='model'
|
||||
)
|
||||
@@ -920,9 +935,6 @@ class DeviceTypeForm(BootstrapMixin, CustomFieldModelForm):
|
||||
'tags',
|
||||
]
|
||||
widgets = {
|
||||
'manufacturer': APISelect(
|
||||
api_url="/api/dcim/manufacturers/"
|
||||
),
|
||||
'subdevice_role': StaticSelect2()
|
||||
}
|
||||
|
||||
@@ -945,11 +957,11 @@ class DeviceTypeBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkE
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=forms.MultipleHiddenInput()
|
||||
)
|
||||
manufacturer = forms.ModelChoiceField(
|
||||
manufacturer = DynamicModelChoiceField(
|
||||
queryset=Manufacturer.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/manufactureres"
|
||||
api_url="/api/dcim/manufacturers"
|
||||
)
|
||||
)
|
||||
u_height = forms.IntegerField(
|
||||
@@ -1048,7 +1060,7 @@ class ConsolePortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class ConsolePortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
@@ -1091,7 +1103,7 @@ class ConsoleServerPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class ConsoleServerPortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
@@ -1134,7 +1146,7 @@ class PowerPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class PowerPortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
@@ -1207,7 +1219,7 @@ class PowerOutletTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class PowerOutletTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
@@ -1276,7 +1288,7 @@ class InterfaceTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class InterfaceTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
@@ -1339,7 +1351,7 @@ class FrontPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class FrontPortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
@@ -1433,7 +1445,7 @@ class RearPortTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class RearPortTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
@@ -1482,7 +1494,7 @@ class DeviceBayTemplateForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class DeviceBayTemplateCreateForm(BootstrapMixin, forms.Form):
|
||||
device_type = forms.ModelChoiceField(
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/'
|
||||
@@ -1653,6 +1665,13 @@ class DeviceRoleCSVForm(forms.ModelForm):
|
||||
#
|
||||
|
||||
class PlatformForm(BootstrapMixin, forms.ModelForm):
|
||||
manufacturer = DynamicModelChoiceField(
|
||||
queryset=Manufacturer.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/manufacturers/",
|
||||
)
|
||||
)
|
||||
slug = SlugField(
|
||||
max_length=64
|
||||
)
|
||||
@@ -1663,9 +1682,6 @@ class PlatformForm(BootstrapMixin, forms.ModelForm):
|
||||
'name', 'slug', 'manufacturer', 'napalm_driver', 'napalm_args',
|
||||
]
|
||||
widgets = {
|
||||
'manufacturer': APISelect(
|
||||
api_url="/api/dcim/manufacturers/"
|
||||
),
|
||||
'napalm_args': SmallTextarea(),
|
||||
}
|
||||
|
||||
@@ -1695,7 +1711,7 @@ class PlatformCSVForm(forms.ModelForm):
|
||||
#
|
||||
|
||||
class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
site = forms.ModelChoiceField(
|
||||
site = DynamicModelChoiceField(
|
||||
queryset=Site.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/sites/",
|
||||
@@ -1721,7 +1737,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
disabled_indicator='device'
|
||||
)
|
||||
)
|
||||
manufacturer = forms.ModelChoiceField(
|
||||
manufacturer = DynamicModelChoiceField(
|
||||
queryset=Manufacturer.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -1734,13 +1750,28 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
)
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
label='Device type',
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-types/',
|
||||
display_field='model'
|
||||
)
|
||||
)
|
||||
cluster_group = forms.ModelChoiceField(
|
||||
device_role = DynamicModelChoiceField(
|
||||
queryset=DeviceRole.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url='/api/dcim/device-roles/'
|
||||
)
|
||||
)
|
||||
platform = DynamicModelChoiceField(
|
||||
queryset=Platform.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/platforms/",
|
||||
additional_query_params={
|
||||
"manufacturer_id": "null"
|
||||
}
|
||||
)
|
||||
)
|
||||
cluster_group = DynamicModelChoiceField(
|
||||
queryset=ClusterGroup.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -1786,16 +1817,7 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
'position': 'face'
|
||||
}
|
||||
),
|
||||
'device_role': APISelect(
|
||||
api_url='/api/dcim/device-roles/'
|
||||
),
|
||||
'status': StaticSelect2(),
|
||||
'platform': APISelect(
|
||||
api_url="/api/dcim/platforms/",
|
||||
additional_query_params={
|
||||
"manufacturer_id": "null"
|
||||
}
|
||||
),
|
||||
'primary_ip4': StaticSelect2(),
|
||||
'primary_ip6': StaticSelect2(),
|
||||
}
|
||||
@@ -2069,31 +2091,29 @@ class DeviceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditF
|
||||
queryset=Device.objects.all(),
|
||||
widget=forms.MultipleHiddenInput()
|
||||
)
|
||||
device_type = forms.ModelChoiceField(
|
||||
device_type = DynamicModelChoiceField(
|
||||
queryset=DeviceType.objects.all(),
|
||||
required=False,
|
||||
label='Type',
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/device-types/",
|
||||
display_field='display_name'
|
||||
)
|
||||
)
|
||||
device_role = forms.ModelChoiceField(
|
||||
device_role = DynamicModelChoiceField(
|
||||
queryset=DeviceRole.objects.all(),
|
||||
required=False,
|
||||
label='Role',
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/device-roles/"
|
||||
)
|
||||
)
|
||||
tenant = forms.ModelChoiceField(
|
||||
tenant = DynamicModelChoiceField(
|
||||
queryset=Tenant.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/tenancy/tenants/"
|
||||
)
|
||||
)
|
||||
platform = forms.ModelChoiceField(
|
||||
platform = DynamicModelChoiceField(
|
||||
queryset=Platform.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -2103,7 +2123,6 @@ class DeviceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditF
|
||||
status = forms.ChoiceField(
|
||||
choices=add_blank_choice(DeviceStatusChoices),
|
||||
required=False,
|
||||
initial='',
|
||||
widget=StaticSelect2()
|
||||
)
|
||||
serial = forms.CharField(
|
||||
@@ -2345,7 +2364,7 @@ class ConsolePortForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class ConsolePortCreateForm(BootstrapMixin, forms.Form):
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/",
|
||||
@@ -2430,7 +2449,7 @@ class ConsoleServerPortForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class ConsoleServerPortCreateForm(BootstrapMixin, forms.Form):
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/",
|
||||
@@ -2529,7 +2548,7 @@ class PowerPortForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class PowerPortCreateForm(BootstrapMixin, forms.Form):
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/",
|
||||
@@ -2647,7 +2666,7 @@ class PowerOutletForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class PowerOutletCreateForm(BootstrapMixin, forms.Form):
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/",
|
||||
@@ -2806,25 +2825,26 @@ class InterfaceFilterForm(DeviceComponentFilterForm):
|
||||
|
||||
|
||||
class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
|
||||
untagged_vlan = forms.ModelChoiceField(
|
||||
untagged_vlan = DynamicModelChoiceField(
|
||||
queryset=VLAN.objects.all(),
|
||||
required=False,
|
||||
label='Untagged VLAN',
|
||||
widget=APISelect(
|
||||
api_url="/api/ipam/vlans/",
|
||||
display_field='display_name',
|
||||
full=True
|
||||
)
|
||||
)
|
||||
tagged_vlans = forms.ModelMultipleChoiceField(
|
||||
tagged_vlans = DynamicModelMultipleChoiceField(
|
||||
queryset=VLAN.objects.all(),
|
||||
required=False,
|
||||
label='Tagged VLANs',
|
||||
widget=APISelectMultiple(
|
||||
api_url="/api/ipam/vlans/",
|
||||
display_field='display_name',
|
||||
full=True
|
||||
)
|
||||
)
|
||||
|
||||
tags = TagField(
|
||||
required=False
|
||||
)
|
||||
@@ -2866,7 +2886,7 @@ class InterfaceForm(InterfaceCommonForm, BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class InterfaceCreateForm(BootstrapMixin, InterfaceCommonForm, forms.Form):
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/",
|
||||
@@ -2916,7 +2936,7 @@ class InterfaceCreateForm(BootstrapMixin, InterfaceCommonForm, forms.Form):
|
||||
tags = TagField(
|
||||
required=False
|
||||
)
|
||||
untagged_vlan = forms.ModelChoiceField(
|
||||
untagged_vlan = DynamicModelChoiceField(
|
||||
queryset=VLAN.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -2925,7 +2945,7 @@ class InterfaceCreateForm(BootstrapMixin, InterfaceCommonForm, forms.Form):
|
||||
full=True
|
||||
)
|
||||
)
|
||||
tagged_vlans = forms.ModelMultipleChoiceField(
|
||||
tagged_vlans = DynamicModelMultipleChoiceField(
|
||||
queryset=VLAN.objects.all(),
|
||||
required=False,
|
||||
widget=APISelectMultiple(
|
||||
@@ -3064,7 +3084,7 @@ class InterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm):
|
||||
required=False,
|
||||
widget=StaticSelect2()
|
||||
)
|
||||
untagged_vlan = forms.ModelChoiceField(
|
||||
untagged_vlan = DynamicModelChoiceField(
|
||||
queryset=VLAN.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -3073,7 +3093,7 @@ class InterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, BulkEditForm):
|
||||
full=True
|
||||
)
|
||||
)
|
||||
tagged_vlans = forms.ModelMultipleChoiceField(
|
||||
tagged_vlans = DynamicModelMultipleChoiceField(
|
||||
queryset=VLAN.objects.all(),
|
||||
required=False,
|
||||
widget=APISelectMultiple(
|
||||
@@ -3166,7 +3186,7 @@ class FrontPortForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
# TODO: Merge with FrontPortTemplateCreateForm to remove duplicate logic
|
||||
class FrontPortCreateForm(BootstrapMixin, forms.Form):
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/",
|
||||
@@ -3344,7 +3364,7 @@ class RearPortForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class RearPortCreateForm(BootstrapMixin, forms.Form):
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/",
|
||||
@@ -3429,7 +3449,7 @@ class ConnectCableToDeviceForm(BootstrapMixin, forms.ModelForm):
|
||||
"""
|
||||
Base form for connecting a Cable to a Device component
|
||||
"""
|
||||
termination_b_site = forms.ModelChoiceField(
|
||||
termination_b_site = DynamicModelChoiceField(
|
||||
queryset=Site.objects.all(),
|
||||
label='Site',
|
||||
required=False,
|
||||
@@ -3555,7 +3575,7 @@ class ConnectCableToRearPortForm(ConnectCableToDeviceForm):
|
||||
|
||||
|
||||
class ConnectCableToCircuitTerminationForm(BootstrapMixin, forms.ModelForm):
|
||||
termination_b_provider = forms.ModelChoiceField(
|
||||
termination_b_provider = DynamicModelChoiceField(
|
||||
queryset=Provider.objects.all(),
|
||||
label='Provider',
|
||||
required=False,
|
||||
@@ -3606,7 +3626,7 @@ class ConnectCableToCircuitTerminationForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class ConnectCableToPowerFeedForm(BootstrapMixin, forms.ModelForm):
|
||||
termination_b_site = forms.ModelChoiceField(
|
||||
termination_b_site = DynamicModelChoiceField(
|
||||
queryset=Site.objects.all(),
|
||||
label='Site',
|
||||
required=False,
|
||||
@@ -3943,7 +3963,7 @@ class DeviceBayForm(BootstrapMixin, forms.ModelForm):
|
||||
|
||||
|
||||
class DeviceBayCreateForm(BootstrapMixin, forms.Form):
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/",
|
||||
@@ -4113,6 +4133,19 @@ class InterfaceConnectionFilterForm(BootstrapMixin, forms.Form):
|
||||
#
|
||||
|
||||
class InventoryItemForm(BootstrapMixin, forms.ModelForm):
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/"
|
||||
)
|
||||
)
|
||||
manufacturer = DynamicModelChoiceField(
|
||||
queryset=Manufacturer.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/manufacturers/"
|
||||
)
|
||||
)
|
||||
tags = TagField(
|
||||
required=False
|
||||
)
|
||||
@@ -4122,18 +4155,10 @@ class InventoryItemForm(BootstrapMixin, forms.ModelForm):
|
||||
fields = [
|
||||
'name', 'device', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description', 'tags',
|
||||
]
|
||||
widgets = {
|
||||
'device': APISelect(
|
||||
api_url="/api/dcim/devices/"
|
||||
),
|
||||
'manufacturer': APISelect(
|
||||
api_url="/api/dcim/manufacturers/"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
class InventoryItemCreateForm(BootstrapMixin, forms.Form):
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.prefetch_related('device_type__manufacturer'),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/",
|
||||
@@ -4142,7 +4167,7 @@ class InventoryItemCreateForm(BootstrapMixin, forms.Form):
|
||||
name_pattern = ExpandableNameField(
|
||||
label='Name'
|
||||
)
|
||||
manufacturer = forms.ModelChoiceField(
|
||||
manufacturer = DynamicModelChoiceField(
|
||||
queryset=Manufacturer.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -4197,14 +4222,14 @@ class InventoryItemBulkEditForm(BootstrapMixin, BulkEditForm):
|
||||
queryset=InventoryItem.objects.all(),
|
||||
widget=forms.MultipleHiddenInput()
|
||||
)
|
||||
device = forms.ModelChoiceField(
|
||||
device = DynamicModelChoiceField(
|
||||
queryset=Device.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/devices/"
|
||||
)
|
||||
)
|
||||
manufacturer = forms.ModelChoiceField(
|
||||
manufacturer = DynamicModelChoiceField(
|
||||
queryset=Manufacturer.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -4364,7 +4389,7 @@ class DeviceVCMembershipForm(forms.ModelForm):
|
||||
|
||||
|
||||
class VCMemberSelectForm(BootstrapMixin, forms.Form):
|
||||
site = forms.ModelChoiceField(
|
||||
site = DynamicModelChoiceField(
|
||||
queryset=Site.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -4466,6 +4491,16 @@ class VirtualChassisFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
||||
#
|
||||
|
||||
class PowerPanelForm(BootstrapMixin, forms.ModelForm):
|
||||
site = DynamicModelChoiceField(
|
||||
queryset=Site.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/sites/",
|
||||
filter_for={
|
||||
'rack_group': 'site_id',
|
||||
}
|
||||
)
|
||||
)
|
||||
rack_group = DynamicModelChoiceField(
|
||||
queryset=RackGroup.objects.all(),
|
||||
required=False,
|
||||
@@ -4479,14 +4514,6 @@ class PowerPanelForm(BootstrapMixin, forms.ModelForm):
|
||||
fields = [
|
||||
'site', 'rack_group', 'name',
|
||||
]
|
||||
widgets = {
|
||||
'site': APISelect(
|
||||
api_url="/api/dcim/sites/",
|
||||
filter_for={
|
||||
'rack_group': 'site_id',
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
class PowerPanelCSVForm(forms.ModelForm):
|
||||
@@ -4581,6 +4608,19 @@ class PowerFeedForm(BootstrapMixin, CustomFieldModelForm):
|
||||
}
|
||||
)
|
||||
)
|
||||
power_panel = DynamicModelChoiceField(
|
||||
queryset=PowerPanel.objects.all(),
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/power-panels/"
|
||||
)
|
||||
)
|
||||
rack = DynamicModelChoiceField(
|
||||
queryset=Rack.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
api_url="/api/dcim/racks/"
|
||||
)
|
||||
)
|
||||
comments = CommentField()
|
||||
tags = TagField(
|
||||
required=False
|
||||
@@ -4593,12 +4633,6 @@ class PowerFeedForm(BootstrapMixin, CustomFieldModelForm):
|
||||
'max_utilization', 'comments', 'tags',
|
||||
]
|
||||
widgets = {
|
||||
'power_panel': APISelect(
|
||||
api_url="/api/dcim/power-panels/"
|
||||
),
|
||||
'rack': APISelect(
|
||||
api_url="/api/dcim/racks/"
|
||||
),
|
||||
'status': StaticSelect2(),
|
||||
'type': StaticSelect2(),
|
||||
'supply': StaticSelect2(),
|
||||
@@ -4697,7 +4731,7 @@ class PowerFeedBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEd
|
||||
queryset=PowerFeed.objects.all(),
|
||||
widget=forms.MultipleHiddenInput
|
||||
)
|
||||
power_panel = forms.ModelChoiceField(
|
||||
power_panel = DynamicModelChoiceField(
|
||||
queryset=PowerPanel.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
@@ -4707,7 +4741,7 @@ class PowerFeedBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEd
|
||||
}
|
||||
)
|
||||
)
|
||||
rack = forms.ModelChoiceField(
|
||||
rack = DynamicModelChoiceField(
|
||||
queryset=Rack.objects.all(),
|
||||
required=False,
|
||||
widget=APISelect(
|
||||
|
||||
Reference in New Issue
Block a user