Prevent editing of SupplierPart fields if initial values are provided

This commit is contained in:
Oliver Walters 2019-04-28 10:57:32 +10:00
parent 101ce53cd3
commit 624c5094c5

View File

@ -406,6 +406,23 @@ class SupplierPartCreate(AjaxCreateView):
ajax_form_title = 'Create new Supplier Part'
context_object_name = 'part'
def get_form(self):
form = super(AjaxCreateView, self).get_form()
# Was the form supplied with initial data?
print("Initial:", form.initial)
print(dir(form))
if form.initial.get('supplier', None):
# Hide the supplier field
form.fields['supplier'].widget.attrs['disabled'] = True
if form.initial.get('part', None):
# Hide the part field
form.fields['part'].widget.attrs['disabled'] = True
return form
def get_initial(self):
""" Provide initial data for new SupplierPart: