Switched to get_ancestors to transverse all parents categories (not only root)

This commit is contained in:
eeintech 2020-11-03 16:58:53 -05:00
parent 5a5a36083e
commit 279d5a00ce

View File

@ -714,20 +714,21 @@ class PartCreate(AjaxCreateView):
# Create part parameters for parent category # Create part parameters for parent category
category_templates = form.cleaned_data['parent_category_templates'] category_templates = form.cleaned_data['parent_category_templates']
if category_templates: if category_templates:
# Get parent category # Get parent categories
category = form.cleaned_data['category'].get_root() parent_categories = form.cleaned_data['category'].get_ancestors()
for template in category.get_parameter_templates(): for category in parent_categories:
# Check that template wasn't already added for template in category.get_parameter_templates():
if template.parameter_template not in template_list: # Check that template wasn't already added
try: if template.parameter_template not in template_list:
PartParameter.create(part=part, try:
template=template.parameter_template, PartParameter.create(part=part,
data=template.default_value, template=template.parameter_template,
save=True) data=template.default_value,
except IntegrityError: save=True)
# PartParameter already exists except IntegrityError:
pass # PartParameter already exists
pass
return self.renderJsonResponse(request, form, data, context=context) return self.renderJsonResponse(request, form, data, context=context)