Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.2.7 on 2025-10-20 13:24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this UniqueConstraint is necessary (I don't think it is), could you please rename this migration to something a bit more informative/less unwieldy (following the usual pattern in NetBox core migrations)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the unique constraint


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.'),
),
]
7 changes: 7 additions & 0 deletions netbox_custom_objects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ class Meta:
"A Custom Object Type with this name already exists."
),
),
models.UniqueConstraint(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary if we already have unique=True on the slug field? I believe it's implicit unless you really want to override the error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that one. Overriding is not necessary then.

Lower("slug"),
name="%(app_label)s_%(class)s_slug",
violation_error_message=_(
"A Custom Object Type with this slug already exists."
),
),
]

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion netbox_custom_objects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down