From 234abb9797f606a54026c6d948737f15b0d1a418 Mon Sep 17 00:00:00 2001 From: Anshul Kamath Date: Sat, 18 Oct 2025 14:26:38 -0400 Subject: [PATCH 1/3] 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 --- netbox_custom_objects/models.py | 7 +++++++ netbox_custom_objects/views.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/netbox_custom_objects/models.py b/netbox_custom_objects/models.py index 858a68a..021308a 100644 --- a/netbox_custom_objects/models.py +++ b/netbox_custom_objects/models.py @@ -209,6 +209,13 @@ class Meta: "A Custom Object Type with this name already exists." ), ), + models.UniqueConstraint( + Lower("slug"), + name="%(app_label)s_%(class)s_slug", + violation_error_message=_( + "A Custom Object Type with this slug already exists." + ), + ), ] def __str__(self): diff --git a/netbox_custom_objects/views.py b/netbox_custom_objects/views.py index a25733b..e7e261a 100644 --- a/netbox_custom_objects/views.py +++ b/netbox_custom_objects/views.py @@ -733,7 +733,7 @@ def get_queryset(self, request): return self.queryset custom_object_type = self.kwargs.get("custom_object_type", None) self.custom_object_type = CustomObjectType.objects.get( - name__iexact=custom_object_type + slug=custom_object_type ) model = self.custom_object_type.get_model_with_serializer() return model.objects.all() From 9c705b3292213530f344555d2c64b371d12a4dd0 Mon Sep 17 00:00:00 2001 From: Anshul Kamath Date: Mon, 20 Oct 2025 09:24:39 -0400 Subject: [PATCH 2/3] fixup! fix(bulk-import): lookup custom object via slug --- ...ox_custom_objects_customobjecttype_slug.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 netbox_custom_objects/migrations/0002_customobjecttype_netbox_custom_objects_customobjecttype_slug.py diff --git a/netbox_custom_objects/migrations/0002_customobjecttype_netbox_custom_objects_customobjecttype_slug.py b/netbox_custom_objects/migrations/0002_customobjecttype_netbox_custom_objects_customobjecttype_slug.py new file mode 100644 index 0000000..42dcf9c --- /dev/null +++ b/netbox_custom_objects/migrations/0002_customobjecttype_netbox_custom_objects_customobjecttype_slug.py @@ -0,0 +1,20 @@ +# Generated by Django 5.2.7 on 2025-10-20 13:24 + +import django.db.models.functions.text +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0019_configrevision_active'), + ('extras', '0133_make_cf_minmax_decimal'), + ('netbox_custom_objects', '0001_initial'), + ] + + operations = [ + migrations.AddConstraint( + model_name='customobjecttype', + constraint=models.UniqueConstraint(django.db.models.functions.text.Lower('slug'), name='netbox_custom_objects_customobjecttype_slug', violation_error_message='A Custom Object Type with this slug already exists.'), + ), + ] From d2c9d4bb686c5aa6d6d78161ecf77a08312969f2 Mon Sep 17 00:00:00 2001 From: Anshul Kamath Date: Mon, 20 Oct 2025 16:28:17 -0400 Subject: [PATCH 3/3] fixup! fix(bulk-import): lookup custom object via slug --- ...ox_custom_objects_customobjecttype_slug.py | 20 ------------------- netbox_custom_objects/models.py | 7 ------- 2 files changed, 27 deletions(-) delete mode 100644 netbox_custom_objects/migrations/0002_customobjecttype_netbox_custom_objects_customobjecttype_slug.py diff --git a/netbox_custom_objects/migrations/0002_customobjecttype_netbox_custom_objects_customobjecttype_slug.py b/netbox_custom_objects/migrations/0002_customobjecttype_netbox_custom_objects_customobjecttype_slug.py deleted file mode 100644 index 42dcf9c..0000000 --- a/netbox_custom_objects/migrations/0002_customobjecttype_netbox_custom_objects_customobjecttype_slug.py +++ /dev/null @@ -1,20 +0,0 @@ -# Generated by Django 5.2.7 on 2025-10-20 13:24 - -import django.db.models.functions.text -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0019_configrevision_active'), - ('extras', '0133_make_cf_minmax_decimal'), - ('netbox_custom_objects', '0001_initial'), - ] - - operations = [ - migrations.AddConstraint( - model_name='customobjecttype', - constraint=models.UniqueConstraint(django.db.models.functions.text.Lower('slug'), name='netbox_custom_objects_customobjecttype_slug', violation_error_message='A Custom Object Type with this slug already exists.'), - ), - ] diff --git a/netbox_custom_objects/models.py b/netbox_custom_objects/models.py index 021308a..858a68a 100644 --- a/netbox_custom_objects/models.py +++ b/netbox_custom_objects/models.py @@ -209,13 +209,6 @@ class Meta: "A Custom Object Type with this name already exists." ), ), - models.UniqueConstraint( - Lower("slug"), - name="%(app_label)s_%(class)s_slug", - violation_error_message=_( - "A Custom Object Type with this slug already exists." - ), - ), ] def __str__(self):