2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-16 17:56:30 +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

@@ -173,3 +173,19 @@ class InvenTreeTree(models.Model):
"""
return self.path
def FilterChildren(queryset, parent):
""" Filter a queryset, limit to only objects that are a child of the given parent
"""
if not parent:
return queryset
elif isinstance(parent,str) and parent.lower() in ['none', 'false', 'null', 'top', '0']:
return queryset.filter(parent=None)
else:
try:
parent_id = int(parent)
return queryset.filter(parent=parent_id)
except:
return queryset