mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Improved FilterChildren function
This commit is contained in:
parent
7fe1c21ebd
commit
22ac5f4f79
@ -177,6 +177,9 @@ class InvenTreeTree(models.Model):
|
|||||||
|
|
||||||
def FilterChildren(queryset, parent):
|
def FilterChildren(queryset, parent):
|
||||||
""" Filter a queryset, limit to only objects that are a child of the given 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:
|
if not parent:
|
||||||
@ -186,6 +189,9 @@ def FilterChildren(queryset, parent):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
parent_id = int(parent)
|
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:
|
except:
|
||||||
return queryset
|
return queryset
|
||||||
|
Loading…
x
Reference in New Issue
Block a user