mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #238: Allow racks with the same name within a site (but in different groups)
This commit is contained in:
@@ -354,6 +354,8 @@ class RackCSVForm(forms.ModelForm):
|
||||
|
||||
site = self.cleaned_data.get('site')
|
||||
group_name = self.cleaned_data.get('group_name')
|
||||
name = self.cleaned_data.get('name')
|
||||
facility_id = self.cleaned_data.get('facility_id')
|
||||
|
||||
# Validate rack group
|
||||
if group_name:
|
||||
@@ -362,6 +364,18 @@ class RackCSVForm(forms.ModelForm):
|
||||
except RackGroup.DoesNotExist:
|
||||
raise forms.ValidationError("Rack group {} not found for site {}".format(group_name, site))
|
||||
|
||||
# Validate uniqueness of rack name within group
|
||||
if Rack.objects.filter(group=self.instance.group, name=name).exists():
|
||||
raise forms.ValidationError(
|
||||
"A rack named {} already exists within group {}".format(name, group_name)
|
||||
)
|
||||
|
||||
# Validate uniqueness of facility ID within group
|
||||
if facility_id and Rack.objects.filter(group=self.instance.group, facility_id=facility_id).exists():
|
||||
raise forms.ValidationError(
|
||||
"A rack with the facility ID {} already exists within group {}".format(facility_id, group_name)
|
||||
)
|
||||
|
||||
|
||||
class RackBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
||||
pk = forms.ModelMultipleChoiceField(queryset=Rack.objects.all(), widget=forms.MultipleHiddenInput)
|
||||
|
||||
Reference in New Issue
Block a user