Skip to content

Commit

Permalink
Correct validation logic (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSheps authored Sep 19, 2024
2 parents 36c9181 + 4296058 commit 08cbea8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions netbox_lifecycle/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,20 @@ def clean(self):
]

if len(selected_objects) == 0:
raise forms.ValidationErrr({
selected_objects[1]: "You must select at least a device or license"
raise forms.ValidationError({
'device': "You must select at least a device or license",
'license': "You must select at least a device or license"
})

if self.cleaned_data.get('license') and not self.cleaned_data.get('device'):
self.cleaned_data['device'] = self.cleaned_data.get('license').device

if self.cleaned_data.get('license') and self.cleaned_data.get('device'):
if self.cleaned_data.get('license').device != self.cleaned_data.get('device'):
raise forms.ValidationError({
'device': 'Device assigned to license must match device assignment'
})


class LicenseForm(NetBoxModelForm):
manufacturer = DynamicModelChoiceField(
Expand Down

0 comments on commit 08cbea8

Please sign in to comment.