From d0b57266ae0532587a2cfccb02e17bf414f9add6 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 17 Mar 2016 11:45:57 -0400 Subject: [PATCH] Prevented an interface from being connected to itself --- netbox/dcim/models.py | 5 +++++ netbox/templates/dcim/interfaceconnection_edit.html | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index bea9a1402..14f1a13e6 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -668,6 +668,11 @@ class InterfaceConnection(models.Model): interface_b = models.OneToOneField('Interface', related_name='connected_as_b', on_delete=models.CASCADE) connection_status = models.BooleanField(choices=CONNECTION_STATUS_CHOICES, default=CONNECTION_STATUS_CONNECTED, verbose_name='Status') + def clean(self): + + if self.interface_a == self.interface_b: + raise ValidationError("Cannot connect an interface to itself") + class Module(models.Model): """ diff --git a/netbox/templates/dcim/interfaceconnection_edit.html b/netbox/templates/dcim/interfaceconnection_edit.html index 8d9a9acd8..784fe3632 100644 --- a/netbox/templates/dcim/interfaceconnection_edit.html +++ b/netbox/templates/dcim/interfaceconnection_edit.html @@ -7,6 +7,18 @@

Connect Interfaces

{% csrf_token %} +
+
+ {% if form.non_field_errors %} +
+
Errors
+
+ {{ form.non_field_errors }} +
+
+ {% endif %} +
+