From 44b2cbd96bf66486e35a2391440b3c9d7505a331 Mon Sep 17 00:00:00 2001
From: Steven H Johnson <shjohnson.pi@gmail.com>
Date: Sun, 26 Jun 2016 12:15:31 -0400
Subject: [PATCH] Do not allow self-referencing nav nodes

---
 htmleditor/forms.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/htmleditor/forms.py b/htmleditor/forms.py
index 6357d3d..eb4bda6 100644
--- a/htmleditor/forms.py
+++ b/htmleditor/forms.py
@@ -88,6 +88,17 @@ class NavigationNodeAdminForm(forms.ModelForm):
 
         return name
 
+    def clean_parent(self):
+        """Do not allow self-referencing nodes"""
+        parent = self.cleaned_data['parent']
+
+        error_msg = "You can't have a node be its own parent."
+
+        if self.instance == parent:
+            raise forms.ValidationError(error_msg)
+
+        return parent
+
     def clean(self):
         "Check to make sure path is unique to prevent IntegrityError"
         cleaned_data = super(NavigationNodeAdminForm, self).clean()
-- 
GitLab