diff --git a/htmleditor/forms.py b/htmleditor/forms.py index 6357d3d1504b92ee7958f00cf1caf57cc059dc5a..eb4bda699456379b8c4d8786fad99ca1c089faf9 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()