diff --git a/categories/base.py b/categories/base.py index 7305cf8..af132bb 100644 --- a/categories/base.py +++ b/categories/base.py @@ -108,10 +108,11 @@ class CategoryBaseAdminForm(forms.ModelForm): # Validate Category Parent # Make sure the category doesn't set itself or any of its children as # its parent. - decendant_ids = self.instance.get_descendants().values_list('id', flat=True) + if self.cleaned_data.get('parent', None) is None or self.instance.id is None: return self.cleaned_data - elif self.cleaned_data['parent'].id == self.instance.id: + decendant_ids = self.instance.get_descendants().values_list('id', flat=True) + if self.cleaned_data['parent'].id == self.instance.id: raise forms.ValidationError(_("You can't set the parent of the " "item to itself.")) elif self.cleaned_data['parent'].id in decendant_ids: