From 22ac5f4f799129f15648c8565c5fafcef95b5cd1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 14 Apr 2017 13:28:37 +1000 Subject: [PATCH] Improved FilterChildren function --- InvenTree/InvenTree/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index 239967e32a..70065edfc6 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -177,6 +177,9 @@ class InvenTreeTree(models.Model): def FilterChildren(queryset, parent): """ Filter a queryset, limit to only objects that are a child of the given parent + Filter is passed in the URL string, e.g. '/?parent=123' + To accommodate for items without a parent, top-level items can be specified as: + none / false / null / top / 0 """ if not parent: @@ -186,6 +189,9 @@ def FilterChildren(queryset, parent): else: try: parent_id = int(parent) - return queryset.filter(parent=parent_id) + if parent_id == 0: + return queryset.filter(parent=None) + else: + return queryset.filter(parent=parent_id) except: return queryset