mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Limit choices for 'parent' field when editing PartCategory
This commit is contained in:
parent
ab76525da2
commit
fb38ddb1b3
@ -404,12 +404,30 @@ class CategoryEdit(AjaxUpdateView):
|
||||
context = super(CategoryEdit, self).get_context_data(**kwargs).copy()
|
||||
|
||||
try:
|
||||
context['category'] = PartCategory.objects.get(pk=self.kwargs['pk'])
|
||||
context['category'] = self.get_object()
|
||||
except:
|
||||
pass
|
||||
|
||||
return context
|
||||
|
||||
def get_form(self):
|
||||
""" Customize form data for PartCategory editing.
|
||||
|
||||
Limit the choices for 'parent' field to those which make sense
|
||||
"""
|
||||
|
||||
form = super(AjaxUpdateView, self).get_form()
|
||||
|
||||
category = self.get_object()
|
||||
|
||||
# Remove any invalid choices for the parent category part
|
||||
parent_choices = PartCategory.objects.all()
|
||||
parent_choices = parent_choices.exclude(id__in=category.getUniqueChildren())
|
||||
|
||||
form.fields['parent'].queryset = parent_choices
|
||||
|
||||
return form
|
||||
|
||||
|
||||
class CategoryDelete(AjaxDeleteView):
|
||||
""" Delete view to delete a PartCategory """
|
||||
|
Loading…
Reference in New Issue
Block a user