Skip to content

Commit 234abb9

Browse files
committed
fix(bulk-import): lookup custom object via slug
custom objects are indexed via the view's url, which is derived from the custom object's slug. the existing bulk import form looked up the custom object by name though, rather than slug. this commit fixes that bad lookup field. the bulk import and bulk delete forms already do this. additionally, we add a slug uniqueness constraint on the custom object type for additional safeguarding
1 parent eba2c7f commit 234abb9

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

netbox_custom_objects/models.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,13 @@ class Meta:
209209
"A Custom Object Type with this name already exists."
210210
),
211211
),
212+
models.UniqueConstraint(
213+
Lower("slug"),
214+
name="%(app_label)s_%(class)s_slug",
215+
violation_error_message=_(
216+
"A Custom Object Type with this slug already exists."
217+
),
218+
),
212219
]
213220

214221
def __str__(self):

netbox_custom_objects/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def get_queryset(self, request):
733733
return self.queryset
734734
custom_object_type = self.kwargs.get("custom_object_type", None)
735735
self.custom_object_type = CustomObjectType.objects.get(
736-
name__iexact=custom_object_type
736+
slug=custom_object_type
737737
)
738738
model = self.custom_object_type.get_model_with_serializer()
739739
return model.objects.all()

0 commit comments

Comments
 (0)