From 0ade52aa3b9820526b7319d8609aa7de504aabe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Sun, 30 Oct 2022 10:18:45 +0100 Subject: [PATCH] Add example for filtering by parent in the Python API docs (#380) * Add example for filtering by parent in the Python API docs * Add example to query the topmost items --- docs/api/python/python.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/api/python/python.md b/docs/api/python/python.md index 64d7066..b850192 100644 --- a/docs/api/python/python.md +++ b/docs/api/python/python.md @@ -95,6 +95,24 @@ items = StockItem.list(api, location=4, part=24) The `items` variable above provides a list of `StockItem` objects. +#### Filtering by parent + +In tree based models the child items could be filtered by using the parent keyword: + +```python +from inventree.part import PartCategory + +child_categories = PartCategory.list(api, parent=10) +``` + +The top level items can can be queried by passing empty string as a parent filter: + +```python +from inventree.part import PartCategory + +parent_categories = PartCategory.list(api, parent='') +``` + ### Item Attributes The available model attributes are determined by introspecting [API metadata](../metadata.md). To view the fields (attributes) availabel for a given database model type within the python interface, use the `fieldNames` and `fieldInfo` methods, as below: