Limit queryset

- Only parts from the supplier
- Exclude parts already in the order
This commit is contained in:
Oliver Walters 2019-06-05 21:13:08 +10:00
parent f4abfc158f
commit aee1ea9e35

View File

@ -71,11 +71,11 @@ class POLineItemCreate(AjaxCreateView):
# Only allow parts from the selected supplier
query = query.filter(supplier=order.supplier.id)
print('limiting queryset')
# Remove parts that are already in the order
query = query.exclude(id__in=[line.part.id for line in order.lines.all()])
form.fields['part'].queryset = query
except PurchaseOrder.DoesNotExist:
print('error')
pass
return form