Limit SupplierPart option in Part edit form

- Only allow selection of SupplierPart that match the Part being edited
This commit is contained in:
Oliver Walters 2019-04-28 23:50:35 +10:00
parent 13756751c3
commit 4e3702384b

View File

@ -169,6 +169,21 @@ class PartEdit(AjaxUpdateView):
ajax_form_title = 'Edit Part Properties'
context_object_name = 'part'
def get_form(self):
""" Create form for Part editing.
Overrides default get_form() method to limit the choices
for the 'default_supplier' field to SupplierParts that reference this part
"""
form = super(AjaxUpdateView, self).get_form()
part = self.get_object()
form.fields['default_supplier'].queryset = SupplierPart.objects.filter(part=part)
return form
class BomExport(AjaxView):