Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #13741: Enforce unique names for inventory items with no parent item #13786

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions netbox/dcim/migrations/0182_inventoryitem_uniqueness_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.5 on 2023-09-15 14:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dcim', '0181_rename_device_role_device_role'),
]

operations = [
migrations.AddConstraint(
model_name='inventoryitem',
constraint=models.UniqueConstraint(condition=models.Q(('parent__isnull', True)), fields=('device', 'name'), name='dcim_inventoryitem_unique_device_name'),
),
]
5 changes: 5 additions & 0 deletions netbox/dcim/models/device_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,11 @@ class Meta:
fields=('device', 'parent', 'name'),
name='%(app_label)s_%(class)s_unique_device_parent_name'
),
models.UniqueConstraint(
fields=('device', 'name'),
name='%(app_label)s_%(class)s_unique_device_name',
condition=Q(parent__isnull=True)
),
)
verbose_name = _('inventory item')
verbose_name_plural = _('inventory items')
Expand Down
Loading