mirror of
https://github.com/jazzband/django-categories.git
synced 2026-03-16 22:30:24 +00:00
Avoid the "Cannot call get_descendants on unsaved Category instances"
ValueError when adding categories in admin interface.
This commit is contained in:
parent
485ff6e6dd
commit
410caf8e79
1 changed files with 3 additions and 2 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue