Fixes result limiting

- Required for index page
This commit is contained in:
Oliver Walters 2021-02-28 20:16:05 +11:00
parent 487794a938
commit 1239d4af16
4 changed files with 28 additions and 3 deletions
InvenTree
part
stock
templates

@ -646,6 +646,20 @@ class PartList(generics.ListCreateAPIView):
queryset = queryset.filter(pk__in=parts_need_stock)
# Optionally limit the maximum number of returned results
# e.g. for displaying "recent part" list
max_results = params.get('max_results', None)
if max_results is not None:
try:
max_results = int(max_results)
if max_results > 0:
queryset = queryset[:max_results]
except (ValueError):
pass
return queryset
filter_backends = [

@ -816,6 +816,18 @@ class StockList(generics.ListCreateAPIView):
print("After error:", str(updated_after))
pass
# Optionally, limit the maximum number of returned results
max_results = params.get('max_results', None)
if max_results is not None:
try:
max_results = int(max_results)
if max_results > 0:
queryset = queryset[:max_results]
except (ValueError):
pass
# Also ensure that we pre-fecth all the related items
queryset = queryset.prefetch_related(
'part',

@ -102,7 +102,7 @@ addHeaderAction('bom-validation', '{% trans "BOM Waiting Validation" %}', 'fa-ti
loadSimplePartTable("#table-latest-parts", "{% url 'api-part-list' %}", {
params: {
ordering: "-creation_date",
limit: {% settings_value "PART_RECENT_COUNT" %},
max_results: {% settings_value "PART_RECENT_COUNT" %},
},
name: 'latest_parts',
});
@ -132,7 +132,7 @@ addHeaderAction('stock-to-build', '{% trans "Required for Build Orders" %}', 'fa
loadStockTable($('#table-recently-updated-stock'), {
params: {
ordering: "-updated",
limit: {% settings_value "STOCK_RECENT_COUNT" %},
max_results: {% settings_value "STOCK_RECENT_COUNT" %},
},
name: 'recently-updated-stock',
grouping: false,

@ -441,7 +441,6 @@ function loadPartTable(table, url, options={}) {
$(table).inventreeTable({
url: url,
sortName: 'name',
method: 'get',
queryParams: filters,
groupBy: false,