2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-15 11:35:41 +00:00

Updated Part API

- categories can now be filtered by parent
- Added FilterChildren func to invenTree.models
This commit is contained in:
Oliver Walters
2017-04-14 13:09:24 +10:00
parent c4b7b80e1a
commit 7fe1c21ebd
5 changed files with 35 additions and 24 deletions

View File

@ -1,6 +1,7 @@
from rest_framework import generics, permissions
import django_filters
from InvenTree.models import FilterChildren
from .models import StockLocation, StockItem
from .serializers import StockItemSerializer, LocationDetailSerializer
@ -70,16 +71,7 @@ class LocationList(generics.ListCreateAPIView):
locations = StockLocation.objects.all()
parent_id = params.get('parent', None)
if parent_id and parent_id.lower() in ['none', 'false', 'null', 'top']:
locations = locations.filter(parent=None)
else:
try:
parent_id_num = int(parent_id)
locations = locations.filter(parent=parent_id_num)
except:
pass
locations = FilterChildren(locations, params.get('parent', None))
return locations