Skip to content

Commit

Permalink
fix: refactor VLAN model by removing device foreign key
Browse files Browse the repository at this point in the history
  • Loading branch information
djothi committed Dec 18, 2023
1 parent ef174e7 commit 36c6f25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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',
),
]
11 changes: 2 additions & 9 deletions netbox_cmdb/netbox_cmdb/models/vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"

0 comments on commit 36c6f25

Please sign in to comment.