mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Part API changes
- Allow filtering parts with null parent (top-level category parts) - Option to include sub-category parts or not
This commit is contained in:
parent
6e65a736e7
commit
f5150f549a
@ -95,6 +95,10 @@ function loadPartTable(table, url, options={}) {
|
||||
query.active = true;
|
||||
}
|
||||
|
||||
// Include sub-category search
|
||||
// TODO - Make this user-configurable!
|
||||
query.cascade = true;
|
||||
|
||||
var columns = [
|
||||
{
|
||||
field: 'pk',
|
||||
|
@ -243,11 +243,24 @@ class PartList(generics.ListCreateAPIView):
|
||||
# Start with all objects
|
||||
parts_list = Part.objects.all()
|
||||
|
||||
if cat_id:
|
||||
cascade = str2bool(self.request.query_params.get('cascade', False))
|
||||
|
||||
if cat_id is not None:
|
||||
|
||||
if isNull(cat_id):
|
||||
parts_list = parts_list.filter(category=None)
|
||||
else:
|
||||
try:
|
||||
cat_id = int(cat_id)
|
||||
category = PartCategory.objects.get(pk=cat_id)
|
||||
|
||||
# If '?cascade=true' then include parts which exist in sub-categories
|
||||
if cascade:
|
||||
parts_list = parts_list.filter(category__in=category.getUniqueChildren())
|
||||
except PartCategory.DoesNotExist:
|
||||
# Just return parts directly in the requested category
|
||||
else:
|
||||
parts_list = parts_list.filter(category=cat_id)
|
||||
except (ValueError, PartCategory.DoesNotExist):
|
||||
pass
|
||||
|
||||
# Ensure that related models are pre-loaded to reduce DB trips
|
||||
|
Loading…
Reference in New Issue
Block a user