From 22c5630af244cd4133d7b59d120de7cba2362ebc Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Thu, 12 Oct 2017 22:42:50 -0500 Subject: [PATCH] [-] Set decendent_ids to empty list if not saved --- categories/base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/categories/base.py b/categories/base.py index af132bb..6d02b87 100644 --- a/categories/base.py +++ b/categories/base.py @@ -111,7 +111,11 @@ class CategoryBaseAdminForm(forms.ModelForm): if self.cleaned_data.get('parent', None) is None or self.instance.id is None: return self.cleaned_data - decendant_ids = self.instance.get_descendants().values_list('id', flat=True) + if self.instance.pk: + decendant_ids = self.instance.get_descendants().values_list('id', flat=True) + else: + decendant_ids = [] + if self.cleaned_data['parent'].id == self.instance.id: raise forms.ValidationError(_("You can't set the parent of the " "item to itself."))