From 36c6f258540a8f58ca3a8c7a08b1e8295d01d4ee Mon Sep 17 00:00:00 2001 From: Djothi Date: Thu, 14 Dec 2023 18:09:58 +0400 Subject: [PATCH] fix: refactor VLAN model by removing device foreign key --- ...vlan_unique_together_remove_vlan_device.py | 19 +++++++++++++++++++ netbox_cmdb/netbox_cmdb/models/vlan.py | 11 ++--------- 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 netbox_cmdb/netbox_cmdb/migrations/0037_alter_vlan_unique_together_remove_vlan_device.py diff --git a/netbox_cmdb/netbox_cmdb/migrations/0037_alter_vlan_unique_together_remove_vlan_device.py b/netbox_cmdb/netbox_cmdb/migrations/0037_alter_vlan_unique_together_remove_vlan_device.py new file mode 100644 index 0000000..8709f61 --- /dev/null +++ b/netbox_cmdb/netbox_cmdb/migrations/0037_alter_vlan_unique_together_remove_vlan_device.py @@ -0,0 +1,19 @@ +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('netbox_cmdb', '0036_deviceinterface'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='vlan', + unique_together={('vid', 'name')}, + ), + migrations.RemoveField( + model_name='vlan', + name='device', + ), + ] diff --git a/netbox_cmdb/netbox_cmdb/models/vlan.py b/netbox_cmdb/netbox_cmdb/models/vlan.py index 3083060..c558ee7 100644 --- a/netbox_cmdb/netbox_cmdb/models/vlan.py +++ b/netbox_cmdb/netbox_cmdb/models/vlan.py @@ -17,13 +17,6 @@ class VLAN(ChangeLoggedModel): validators=(MinValueValidator(VLAN_VID_MIN), MaxValueValidator(VLAN_VID_MAX)), ) name = models.CharField(max_length=64) - device = models.ForeignKey( - to="dcim.Device", - on_delete=models.CASCADE, - related_name="%(class)sdevice", - null=False, - blank=False, - ) description = models.CharField(max_length=100, blank=True) tenant = models.ForeignKey( to="tenancy.Tenant", @@ -34,10 +27,10 @@ class VLAN(ChangeLoggedModel): ) def __str__(self): - return f"{self.device.name}--{self.name}" + return f"{self.name}" class Meta: ordering = ["vid"] - unique_together = ("device", "name") + unique_together = ("vid", "name") verbose_name = "VLAN" verbose_name_plural = "VLANs"