Switch to FlexibleModalChoiceField for lag...still broken clean_lag method

This commit is contained in:
Joseph Kennedy 2017-08-26 21:39:53 -04:00
parent 6e1af855bf
commit 23e20964e9

View File

@ -1541,9 +1541,11 @@ class InterfaceCSVForm(forms.ModelForm):
name = forms.CharField( name = forms.CharField(
help_text='Name of interface' help_text='Name of interface'
) )
lag = forms.CharField( lag = FlexibleModelChoiceField(
required=False, queryset=Interface.objects.filter(form_factor=IFACE_FF_LAG),
help_text='Lag Name' to_field_name='name',
help_text='Lag Name or ID of interface',
error_messages={'invalid_choice': 'Lag not found.'}
) )
mac_address = forms.CharField( mac_address = forms.CharField(
required=False, required=False,
@ -1598,13 +1600,12 @@ class InterfaceCSVForm(forms.ModelForm):
def clean_lag(self): def clean_lag(self):
device = None device = None
if self.cleaned_data['device'] is not None: lag_name = self.data.get('lag')
if self.data['device'] is not None:
lag = Interface.objects.filter( lag = Interface.objects.filter(
device=self.cleaned_data['device'], form_factor=IFACE_FF_LAG).get( device=self.data.get('device'), form_factor=IFACE_FF_LAG).get(
lag=self.cleaned_data['lag'] lag=lag_name
) )
if not lag: if not lag:
return None return None
return lag return lag