Improve / simplify logic for file attachments against test result object

This commit is contained in:
Oliver Walters committed 2020-05-23 11:30:42 +10:00
1 parent 50987f47b0
commit e63342418f
6 files changed
+29 -60

No files matched your search

-13
View File
@@ -292,17 +292,6 @@ class StockItemTestResultCreate(AjaxCreateView):
form = super().get_form()
form.fields['stock_item'].widget = HiddenInput()
# Extract the StockItem object
item_id = form['stock_item'].value()
# Limit the options for the file attachments
try:
stock_item = StockItem.objects.get(pk=item_id)
form.fields['attachment'].queryset = stock_item.attachments.all()
except (ValueError, StockItem.DoesNotExist):
# Hide the attachments field
form.fields['attachment'].widget = HiddenInput()
return form
@@ -320,8 +309,6 @@ class StockItemTestResultEdit(AjaxUpdateView):
form = super().get_form()
form.fields['stock_item'].widget = HiddenInput()
form.fields['attachment'].queryset = self.object.stock_item.attachments.all()
return form