Closes #1744: Allow associating a platform with a specific manufacturer

This commit is contained in:
Jeremy Stretch
2017-12-19 16:15:26 -05:00
parent 64dcd4eb99
commit 3e355830fe
8 changed files with 97 additions and 15 deletions

View File

@@ -677,7 +677,7 @@ class PlatformForm(BootstrapMixin, forms.ModelForm):
class Meta:
model = Platform
fields = ['name', 'slug', 'napalm_driver', 'rpc_client']
fields = ['name', 'slug', 'manufacturer', 'napalm_driver', 'rpc_client']
class PlatformCSVForm(forms.ModelForm):
@@ -685,9 +685,10 @@ class PlatformCSVForm(forms.ModelForm):
class Meta:
model = Platform
fields = ['name', 'slug', 'napalm_driver']
fields = ['name', 'slug', 'manufacturer', 'napalm_driver']
help_texts = {
'name': 'Platform name',
'manufacturer': 'Manufacturer name',
}
@@ -797,6 +798,11 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm):
# can be flipped from one face to another.
self.fields['position'].widget.attrs['api-url'] += '&exclude={}'.format(self.instance.pk)
# Limit platform by manufacturer
self.fields['platform'].queryset = Platform.objects.filter(
Q(manufacturer__isnull=True) | Q(manufacturer=self.instance.device_type.manufacturer)
)
else:
# An object that doesn't exist yet can't have any IPs assigned to it