Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Make 'parent' field not required

Marcin Gębalaed67856f602c
diff --git a/saleor/dashboard/category/forms.py b/saleor/dashboard/category/forms.py
index 522f5b0865..bfe1150370 100644
--- a/saleor/dashboard/category/forms.py
+++ b/saleor/dashboard/category/forms.py
@@ -12,12 +12,13 @@ class CategoryForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(CategoryForm, self).__init__(*args, **kwargs)
- self.fields['parent'] = TreeNodeChoiceField(queryset=Category.objects.all())
+ self.fields['parent'] = TreeNodeChoiceField(queryset=Category.objects.all(), required=False)
def clean_parent(self):
parent = self.cleaned_data['parent']
- if parent == self.instance:
- raise forms.ValidationError(_('A category may not be made a child of itself'))
- if self.instance in parent.get_ancestors():
- raise forms.ValidationError(_('A category may not be made a child of any of its descendants.'))
+ if parent:
+ if parent == self.instance:
+ raise forms.ValidationError(_('A category may not be made a child of itself'))
+ if self.instance in parent.get_ancestors():
+ raise forms.ValidationError(_('A category may not be made a child of any of its descendants.'))
return parent